Hot answers tagged

1

It means that there is no default return value for your function outside of the for loop. You are assuming that loop will always run, but, what if an empty string ends up getting submitted? The compiler makes no such assumptions, so you need to make sure that there is a return path that will be followed if the return statement inside your loop is never ...


1

The actual problem isn't in the isdigit statement. It's in the for statement. for(int i = 0, n = (strlen(argv[1])); i < n; i++) If there is no parameter, then argv[1] doesn't exist. So, strlen throws a seg fault. The code needs to check argc before it does anything with argv. If this answers your question, please click on the check mark to accept. Let's ...


1

Its a simple and common issue with new programmers. ;-) Yes, argv[] is an array of strings. So, argv[1] is a string. Now, say that argv[1] contains the string "cat". Then argv[1][0] contains the char 'c', argv[1][1] contains 'a', argv[1][2] contains 't' and argv[1][3] contains the end of string marker, '\0'. That last one is very important, ...


1

You can't reprompt a user for command line arguments. You will have to exit the program after printing the usage.


1

Perhaps a review of the class material on command line arguments is in order? https://cs50.harvard.edu/x/2020/notes/2/#command-line-arguments


1

I only needed to add some extra braces for the if condition beneath the for loop.


1

Two related problems. First, 'a' = 97, 'A' = 65, so you're subtracting the wrong value for lower case letters. Since the ASCII numbers of upper case and lower case letters differ by 32, and 32 - 26 = 6, guess what happens. Second, the code doesn't check whether the letter being encoded is upper or lower case at all. As written, this code will only encode ...


Only top voted, non community-wiki answers of a minimum length are eligible