5

You have popped with many questions at the same time. Lets start with the simplest one. What's the relation between return value of a function and command line arguments? You don't return 1 because you have 1 command line argument. The return value of any function(including main()) is almost independent of the arguments passed (unless you do something ...


3

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 comprehend it, here's what those two items do. argc is a built-in variable in C, one of the few. It tells the program the number of parameters that were in the call to ...


2

You're not supposed to get a number from the user that's to two decimal places although you could do that maybe by getting the number as a string then converting it.


2

The command line argument doesn't get passed to main via GetInt(). It gets passed via the command line. You do something like ./caesar 13 And 13 is stored in argv[1] Watch the walkthroughs and the shorts for command line arguments


2

You forgot to include the relevant code. You probably call your check function with a NULL pointer. This might happen for example if you use argv[1] before checking whether argc is greater than 1 (or here: equals 2), otherwise that array element wouldn't exist, and could have any value.


1

The code is working correctly. If it's giving a file size of 0, the file size really is zero. Maybe it was overwritten? If the file weren't there, it would gen an error. Why are you getting a file size when changing to argv[0]? Simple. The code is using the name of the executable file recover. If this answers your question, please click on the check mark ...


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 ...


1

Consider the for loop in your vote() function: It compares the candidate name with the name introduced by the voter. In the very first pass (i = 0) what happens when the candidate name and the name introduced are not the same?


1

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 character as an argument.


1

The code is actually testing for non-alpha keys. The problem is that it is prompting for the plaintext before checking the key. It's a sequence issue. As a side issue, consider how you might make the code more efficient. For example, the code is structured like this: if(argc==2) { //the bulk of the program } else if(argc!=2) { printf("Usage: ./...


1

in case you run your program as follows: ./caesar key you have 2 command-line arguments (i.e., argv[0] containing the name of the executable, in this case ./caesar and argv[1] containing key). so yes, key in this case is the second argument. the third argument, argv[2], in this case, is NULL according to the C standard. this is why you get a segmentation ...


1

in C, you are allowed to declare more than one variable of the same type by specifying the type, then listing variables names, and optionally initialize them, in comma-separated form. so int j = 0, n = strlen(argv[i]) declares a couple of variables, j and n, both of type int and initializes the former with a 0 and the latter with the value returned from the ...


1

Actually, he did declare n as an int. int j=0, n=strlen(argv[i]) declares both j and n as integers. It is just like the following statements: int num, num2, num3; char x, y; int foo = 1, bar, goo = 2; Each of these statements declares multiple vars, some of which are initialized. Note that the vars are separated by commas, and the type (int, char) applies ...


1

Yes, you're not giving the right parameters. There are two ways to invoke speller: ./speller <file_to_test> ./speller <dictionary_file> <file_to_test> You've been invoking with one or both parameters that don't lead to files. If you invoke with only one parameter, it will use the default dictionary, large. If you invoke with both ...


1

I'll give you part of that, with an explanation. Command line arguments are the parameters that follow the invocation of a program. For example, ./myprogram shows the program myprogram being executed, with no command line parameters. The following, ./myprogram foo bar demonstrates the command line used to execute myprogram with two command line ...


1

Sure, it is possible. But you will have to check if the arguments given to main are valid for your program, and also you will have to convert the arguments to the type you need, since the arguments are strings. Example: #include <stdio.h> #include <cs50.h> #include <string.h> int main(int argc, char* argv[]) { if (argc == 1) { ...


1

The problem is not with the argv only but with every input from the user, that is not checked. For example say you define a string that will hold 10 characters (let's call it buffer). Then you ask the user to give you a string, but instead of giving you a string with 9 characters at most (plus the '\0') he gives you a string that is 100 characters long. Your ...


1

It's up to you to determine what you use argv[] for. In this program, you should expect the key to be entered on the command line (it will be stored in argv[1]) and for the plain text to be entered by the user once the program starts (using GetString() is a good way to do this).


1

A function either returns a value (has a return type) or not (its return type is void). A function that has a return type must return a value. A function whose return type is void mustn't return a value. The main function is a special function. It's the starting point of your program and it returns an int (has a return type of int). By convention, we ...


1

Functions doesn't really need to return values, you can always set them as void. The other returns you mention are usually used as exit codes, a 0 means that there was no issue with the program and a 1 that there was. I.e: User enters 1 argument instead of 2 needed -> shows help -> exits with return 1 That would be for a program that exits if the ...


1

main is a special function. It's the starting point of a C program — it's called somehow magically when you execute the program from the terminal by typing its name in as follows ./programName main can be declared to receive command-line arguments. Command-line arguments are special type of arguments in a sense that they're passed to your program via the ...


1

Does anybody know why? Because you're trying to access a string that doesn't really exist in case it's not passed as a command-line argument to your program! So you should first check whether you get the correct number of command-line arguments passed to your program then start dealing with them. Also, not really sure why I should return 1 if an ...


1

Mate, I understand at times silly things turns frustrating. Especially when working on big project. But you need to take care of small things. As I noticed in the following line int key = atoi(argv[1]) you forgot semi-colon. Please correct the line as follows int key = atoi(argv[1]); Next, assume that user simply forgot about the command line arguments. ...


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