5 votes
Accepted

Segmentation Fault and Returning 1

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 ...
user avatar
  • 3,316
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 ...
user avatar
  • 63.5k
2 votes
Accepted

PSET5 Dictionary - error : Could not open texts files

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 ...
user avatar
  • 63.5k
2 votes

caesar.c command line argument not stored in argv

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 ...
user avatar
  • 1,677
2 votes

How do I ensure that the user input in greedy is given to two decimal places?

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.
user avatar
  • 17.4k
2 votes
Accepted

null pointer passed as argument 1

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 ...
user avatar
  • 20.7k
1 vote
Accepted

Why does `size` = `0` occur?

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 ...
user avatar
  • 63.5k
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 ...
user avatar
  • 63.5k
1 vote
Accepted

Pset3: Plurality; Code doesn't consider command line arguments expect the first one!

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 ...
user avatar
  • 1,561
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 ...
user avatar
1 vote
Accepted

not satisfying the condition for input

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 ...
user avatar
  • 63.5k
1 vote
Accepted

is `key` in `./caesar key` my second or third command-line argument?

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 ...
user avatar
  • 17.4k
1 vote

Question on pset2 youtube video(command-line argument)

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 ...
user avatar
  • 17.4k
1 vote
Accepted

Question on pset2 youtube video(command-line argument)

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 = ...
user avatar
  • 63.5k
1 vote
Accepted

int GetInt(void) and command line arguments

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 ...
user avatar
  • 17.4k
1 vote

Segmentation Fault and Returning 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 ...
user avatar
  • 17.4k
1 vote

Segmentation Fault and Returning 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[...
user avatar
  • 207
1 vote
Accepted

Can anyone give me an example of code without a command-line-argument and code with a command-line-argument?

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 ...
user avatar
  • 63.5k
1 vote

Main argument input definitions

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 ...
user avatar
  • 1,369
1 vote

Command line argument - buffer over read

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 avatar
  • 7,326
1 vote

Check50 message "Can't check until the frown turns upside down"

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 ...
user avatar
  • 18.4k
1 vote
Accepted

Do I have to return a value when checking all command line arguments

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 ...
user avatar
  • 17.4k
1 vote

Do I have to return a value when checking all command line arguments

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

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