Reputation: 19
i'm trying to deliver parameters for a program with the command line. I want, that the program is working as shown now: - start the program with parameter "program.exe " - then the should be useable in the programm How can i approach this thing?
Here is the essential part of my programm:
int main(){
int length;
unsigned int i=0;
length=strlen(word);
for(i=0;i<length;i++) {
printf("%d",word[i]);
}
}
And i wanted to add this word[] parameter via command line. Thanks!
Upvotes: 0
Views: 92
Reputation: 27210
For command line arguments Use argv and argc
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char* argv[] )
{
int i;
printf("argc is %d\n",argc);
for(i = 1; i < argc ; i++){
printf("%d \n", atoi(argv[i]));
}
}
Run your program as
./a.out 10 20 30
argc is 4
10
20
30
Upvotes: 1
Reputation: 11
int main( int argc, char* argv[] ) {
return 0;
}
Upvotes: 1