Hot answers tagged

7 votes
Accepted

pset6 - caesar - check50 error: "expected exit code 1, not 0"

main in Python no longer has a special meaning, but is a regular function, its name only chosen to conform to conventions based in C. Try exit(1) instead of return 1. Relevant python docs: https://...
  • 20.7k
6 votes

How to handle "lack of argv[1]"

GAR, figured it out. I didn't take the details of "your program should yell at you" literally. This works now. if (argc != 2) { printf("YOU SCREWED UP!"); return 1; }
6 votes
Accepted

char* text = (argc == 3) ? argv[2] : argv[1];

Yes, you are correct. char* text = (argc == 3) ? argv[2] : argv[1]; actually means char* text = ((argc == 3) ? argv[2] : argv[1]); i.e. assign some value to char *text with the help of Ternary ...
  • 3,346
3 votes
Accepted

week3 lecture very beginning

If I understand your question correctly, and it's "what is the role of argc" the answer is that we need it to know how many arguments were passed to main from the command line. So if the command was ./...
  • 7,356
3 votes
Accepted

What does argc and argv have to do with cryptography? Why are we learning about these arguments?

What do argc and argv have to do with the subject of cryptography? Nothing. But they DO have a lot to do with how you get data into a program when it is started. Just in case you didn't ...
  • 64.7k
3 votes

Can someone explain me the point of the "int k = atoi((argv[1]);"?

In this problem set, you are not asked to get input from the user after the program starts but rather get it using command line arguments. command line arguments are basically just input that the user ...
2 votes
Accepted

length of argv always change to 1?

Actually, it's not always changing to 1 on the last line. The result is always dependent on the input to argv[1]. Specifically, the last number printed depends on where the first 'a' appears in the ...
  • 64.7k
2 votes

Can someone explain me the point of the "int k = atoi((argv[1]);"?

You aren't supposed to take input from the user using GetInt. Rather, you are supposed to take input as command-line arguments. As for your question Why do we need to convert the key to int after ...
  • 17.4k
2 votes
Accepted

Error return 1? Caesar

you need to follow the pset specs literally as it's machine-graded. if argv[1]<>1, you need to return 1 right away instead of giving an error message
  • 1,415
1 vote
Accepted

PSET2 Caesar - Stuck at 'isdigit' step: Do I need to learn about pointers, or is something else going on?

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] ...
  • 64.7k
1 vote
Accepted

Strange CL output

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 ...
  • 64.7k
1 vote
Accepted

Having problems with Pset2, argv[1]: program doesn't 'see' it

It's because you have return 1; after your if statement, that will just exit the program in that line and will not proceed to the next lines. That return should be inside your if statement therefore ...
  • 711
1 vote
Accepted

CS50 Vigenere Segmentation Fault

It looks like it will fail here else if (isalpha(argv) == 0) (I did not read the code further). argv is an array of strings. Review the man page for isalpha to be reminded that it takes a single ...
1 vote
Accepted

Resize infile won't read from argv

Let's look at some of the code: char *tmp = argv[1]; tmp[strlen(argv[1]) + 1] = '\0'; ... for (int i = 0, n = strlen(tmp); i < n; i++) { if (!isdigit(tmp[i])){ fprintf(stderr, "Usage:...
  • 64.7k
1 vote

error: unused parameter 'argv'

It's quite literally what it says. First, understand that all warnings are treated as errors because of one of the flags in the compile statement. This would otherwise just be a warning. Now to the ...
  • 64.7k
1 vote

Assing argv[1] to a string variable (vigenere)

The best and most efficient way is to out grow CS50.h use char* newString = argv[1]; argv will always be there so you might as well point to it or use it.
  • 186
1 vote

Assing argv[1] to a string variable (vigenere)

string keyword = argv[1]; will work because you are assigning the address of string argv[1] to keyword. You can now treat keyword as a char array and access the individual characters as keyword[i]. ...
  • 64.7k
1 vote
Accepted

How to check string argv[] for errors?

Your program is actually working as designed. What you're probably overlooking is how the OS shell is handling the inputs to the program. Single quotes, double quotes and the single back quote (the ` ...
  • 64.7k
1 vote

How to check string argv[] for errors?

If you're trying to printf an apostrophe, or other special characters in C, you need to enter the proper escape sequence. You've already seen an example of this...the \n that you have to type in order ...
1 vote

How to handle "lack of argv[1]"

I had the same error until I moved my declared variables AFTER the if... if (argc !=2) { printf("Oops! Only 2 arguments allowed"); return 1; } int k = atoi(argv[1]); string p;

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