Questions tagged [argc]

The number of arguments given to the program, found as a parameter to main in some languages, notably C.

argc stands for argument count, and represents the number of arguments given to the program, or main, in a command-line. It is used in conjunction with .

Keep in mind that argc also counts the program name.

Notable Stack Overflow questions:

243 questions
-1
votes
1 answer

Error malloc on string from argv

I'm using a string received from the arg to return another string with characters shuffled. int size = strlen(argv[4]); char* res = malloc(size+1); Then res is filled with the characters of argv[4], but when I type 'test' in the console, it returns…
Théo Winterhalter
  • 4,908
  • 2
  • 18
  • 34
-1
votes
2 answers

Trouble with argc and argv

I am trying to add command line arguments to my programs. So I was experimenting and cannot figure out this intellisense warning for the life of me. It keeps on saying it is expecting a ')', but I don’t have any idea why. Here is the code it does…
MrPickle5
  • 522
  • 4
  • 9
  • 31
-1
votes
2 answers

Argv parameters conversion

Possible Duplicate: Converting string to integer C I wanted to convert a number I received from the command argv[1] into an "int". I know the argv is stored as a string, but how can I get an integer value from them. Supposing argv[1] = 10.
Josh
  • 3,231
  • 8
  • 37
  • 58
-2
votes
1 answer

How can i pass the content of file as an arguments to some function?

given file a.txt how can I pass the content of this file as arguments to the main function ? for example: a.txt: a b c d e and the main function is: int main(int argc, char *argv[]); And I want to pass the content of this a.txt file as arguments…
-2
votes
1 answer

Factorial program displaying the inital value and not the factorial itself

Below is my program to calculate the factorial of a given int. It compiles but only displays the initial value of the fact. It most likely has something to do with the if(argc>1) statement, but that is required for the assignment. #include…
-2
votes
2 answers

Why is this my code producing a segmentation fault when there is only argc[1]?

I'm taking a intro CS course (CS50x) and came across a slight problem. Why is this C code producing a segmentation fault when there is only argc[1]? It should print the statement. Why won't it print the error? Thanks in advance! int main(int argc,…
-2
votes
1 answer

Passing in filename from command line to read file content

I have a function ./transform that needs to take in two command line arguments for an input and output file. Like so: ./transform "inputfile" "outputfile" I am then trying to read the file using fopen to store each character in the file into a…
jasonsogan
  • 11
  • 1
  • 4
-2
votes
1 answer

How to split a string into words?

I am trying to split strings into words. Can anyone help me on how to implement it without using strtok and another function other than main? void main() { int i; int myargc = 1; char *myargv[256]; char buff[100]; int len = 0; …
jsrookie
  • 15
  • 1
  • 4
-2
votes
1 answer

realloc(): invalid pointer error when using argc and argv

As part of an exercise, I am developing a small grep-like program in C which is supposed to receive a string and some file names in order to look for that string in the referred files. I got it working by hardcoding the name of the file and the…
Alfonso Jiménez
  • 1,235
  • 1
  • 13
  • 24
-2
votes
3 answers

copying binary files - source and target in c programming

hello guys i made a program which copying binary files, but i have a problem: when im trying to copy the field of the source file to the target file its removing all the field of the target file. how can i solve this problem? #include…
-2
votes
2 answers

printing using argv and argc

here is a program which printing some information about my self in this program if the user scanning /n its printing the name and etc. but when i'm running this program using gcc its printing nothing at all. i need to scan the parameters using argv…
-2
votes
2 answers

subscripted value is neither array nor pointer nor vector with argv

I have this code.c in ubuntu in terminal but when I compile it with gcc this error appeared cod2.c: In function ‘main’: cod2.c:9:11: error: subscripted value is neither array nor pointer nor vector why is that? int main(int argc , char ** argv){ …
patric
  • 17
  • 10
-2
votes
1 answer

C++ Create file if argc==2?

I really cannot figure out what is wrong here... I want the code to create a file when I type one argument in the terminal. It works fine if argc is set to 1, but not anything above that. Any help is much appreciated ! Cheers & a nice sunday…
-2
votes
5 answers

How to write a "argv" and "argc"

I understand what argv and argc do and how they're used, but I am in need to recreate them. In C, how would you write a function to imitate them.
-2
votes
2 answers

Comparing two files in c

As the title says I need to compare 2 files.If a line comes by ,that isnt the same between this 2 files,print that line (From both files).The code is giving a don't send error.I can't seem to be able to find the error in my code. #include…
Lind
  • 277
  • 2
  • 5
  • 16