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 ...
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 ...
The command line argument doesn't get passed to main via GetInt(). It gets passed via the command line.
You do something like
And 13 is stored in argv
Watch the walkthroughs and the shorts for command line arguments
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 before checking whether argc is greater than 1 (or here: equals 2), otherwise that array element wouldn't exist, and could have any value.
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? Simple. The code is using the name of the executable file recover.
If this answers your question, please click on the check mark ...
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 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[i].
Looks like there's a bunch of missing code here that has yet to be added. ;-)
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?
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.
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:
//the bulk of the program
in case you run your program as follows:
you have 2 command-line arguments (i.e., argv containing the name of the executable, in this case ./caesar and argv containing key). so yes, key in this case is the second argument.
the third argument, argv, in this case, is NULL according to the C standard. this is why you get a segmentation ...
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 ...
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 ...
Yes, you're not giving the right parameters. There are two ways to invoke speller:
./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 ...
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,
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 ...
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.
int main(int argc, char* argv)
if (argc == 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 ...
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) and for the plain text to be entered by the user once the program starts (using GetString() is a good way to do this).
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 ...
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 ...
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
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 ...
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 ...
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)
you forgot semi-colon. Please correct the line as follows
int key = atoi(argv);
Next, assume that user simply forgot about the command line arguments. ...