Questions tagged [argc]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
2answers
2k views

How to handle “lack of argv[1]”

I have my code set up so that if argc doesn't equal 2 the main function will return 1. Per the specs I thought. But I keep getting the error that I didn't "handle lack of argv[1]". if (argc != 2) ...
1
vote
1answer
116 views

why argc is not counting all commands?

In command line argument example when we run program, it count all cmd argument but in case argc is 2 ? why not 4 ?
0
votes
3answers
1k views

Segmentation Fault and Returning 1

If I declare int key before my if (argc != 2), I get a segmentation fault (core dumped) message when I run the program with only one command-line argument. However if I declared int key after the if ...
0
votes
2answers
2k views

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

I know that the answer seems obvious but I will explain further the reason for my question: in my program I only used for the key int k = GetInt() without the argv, argc etc. and the program seems to ...
0
votes
1answer
982 views

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

Could someone explain me what the line in the title actually does? Am I correct if argc is 3 char* text is argv[2] else char* text is argv[1] ? If so, how do the operators work in this ...
0
votes
1answer
49 views

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

I understand what these arguments do--take inputs before the program starts to in some way influence the program. But they seem to have been shoe-horned into the lecture. David moves on from this ...
0
votes
1answer
30 views

week3 lecture very beginning

Week3 Lecture: A student asked a question of my mind how do computer know about the argc ? I really don't understand how is this argc working In case we printed "zymla" we gave argv[1] as our first ...
0
votes
2answers
389 views

How to check string argv[] for errors?

hope I can get some help here. I'm only at week 3 in CS50 and wanted to play around with command-line arguments a bit before moving on. I got this working (diagonalizing input), but couldn't figure ...
0
votes
1answer
43 views

PSet 2 - Why will it still pass negative numbers?

I am working on pset2 Caesar. I have everything done except for the fact that my program allows you to pass negative numbers as a key. Here is my code: #include <cs50.h> #include <ctype.h>...
0
votes
1answer
284 views

caesar argc … help me get started

Ok so i just started caesar and i don't know whether I'm headed in the right direction or not, if not i just need someone to point me the right way,and yes i have seen the walkthrough. so heres my ...
0
votes
1answer
75 views

How can I display “< key>” on the same line if argc != 2?

How can I display "< key>" on the same line if argc != 2? Example: check50 2014.fall.pset2.caesar caesar.c