0

I was testing my code to see if the command line argument's characters are digits but after plugging a random argument that was a mix of letters and numbers, I obtained a strange output. See what you make of it and if you have any idea whats going on, I'd appreciate them

#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>


int main(int argc, string argv[])
{
  if (argc == 2) {
    for (int i = 0, n = strlen(argv[1]); i < n; i++) {


       if (i) {
         printf("%s\n", argv[i]);
       }
    }
    return 0;

  } else if (argc > 2) {
    printf("%s", "Usage: ./caesar key \n");

  } else {
    printf("%s", "Usage: ./caesar key\n");

  }

Command Line Output:

$ ./caesar 3uhhhlyffx5bp953azmk976rrctfuuu
3uhhhlyffx5bp953azmk976rrctfuuu 
(null) 
LC_ALL=C.UTF-8 
SSH_CONNECTION=192.168.100.119 47830 192.168.151.248 22 
ISOUTPUTPANE=0 
FLASK_APP=application.py 
LANG=C.UTF-8 
DISPLAY=:0 
EDITOR=nano 
NODE_PATH=/home/ubuntu/.c9/node_modules 
GEM_HOME=/home/ubuntu/.gem 
JAVA_HOME=/opt/jdk-12.0.1 
FLASK_DEBUG=0 
C9_PID=9c83620857724cd7bc928021c3765a39 
CFLAGS=-ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow 
S_COLORS=auto 
NODE_ENV=dev 
CLASSPATH=.:/usr/share/java/cs50.jar 
CC=clang 
FLASK_ENV=development 
USER=ubuntu 
C9_USER=studentRole 
APPLICATION_ENV=dev 
PWD=/home/ubuntu/pset2/caesar 
CHECK50_WORKERS=1 
HOME=/home/ubuntu 
LC_CTYPE=C.UTF-8 
C9_HOSTNAME=6c2d1f21-c253-4199-8cad-61c19b30d4f4-ide.cs50.xyz 
SSH_CLIENT=192.168.100.119 47830 22 
TMUX=/tmp/tmux-1000/cloud92.2,4585,0 
1

I have no idea what this code is doing. But that doesn't really matter.

You said that the intent is to test the chars in argv[1] to see if they're digits. Well, there's absolutely no code here to do that. I don't see any calls to isdigit() or anything that checks argv[1][i].

Looks like there's a bunch of missing code here that has yet to be added. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks A lot. I actually ended pasting the unfinished code because I was so curious bout that command line output, but thanks for the arg[v][i] tip, can't believe I didn't think of that XD – tinomutendaishe msakwa Oct 12 '20 at 13:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .