T
Tim Cambrant
Hi, I've been experimenting with C for about a week now and I've read the
tutorial at http://www.geocities.com/tom_torfs/cintro.html, so i feel quite
sure of the syntax and the program flow now. However, I don't seem to have
the right understanding of how arrays really work, since this test-program
of mine doesn't compile right.
-------------
#include <stdio.h>
#include <string.h>
int parse_args(char cmd_arg[]);
int main(int argc, char *argv[])
{
int i, arg_check;
for (i=1; i < argc; i++) {
arg_check = parse_args(argv);
if (arg_check == 1)
printf("Error: %s is an unknown command.", argv);
}
return 0;
}
int parse_args(char cmd_arg[])
{
switch(cmd_arg) {
case 'test1':
printf("%s\n", cmd_arg);
return 0;
case 'test2':
printf("%s\n", cmd_arg);
return 0;
default:
return 1;
}
}
-------------
When I try to compile this i get these errors:
$ gcc -Wall test.c -o test
test.c: In function `parse_args':
test.c:22: switch quantity not an integer
test.c:23: character constant too long
test.c:26: character constant too long
test.c:24: warning: unreachable code at beginning of switch statement
$
I think it all depends on the fact that I don't know how to format the code
correctly when handling arrays (Where to use "array[]", "array[x]" or
"array"). I think I can recall having problems with the same thing a year
ago when giving C++ a go. What am I doing wrong?
I think you'll understand the programs purpose, so I won't have to explain
it.
tutorial at http://www.geocities.com/tom_torfs/cintro.html, so i feel quite
sure of the syntax and the program flow now. However, I don't seem to have
the right understanding of how arrays really work, since this test-program
of mine doesn't compile right.
-------------
#include <stdio.h>
#include <string.h>
int parse_args(char cmd_arg[]);
int main(int argc, char *argv[])
{
int i, arg_check;
for (i=1; i < argc; i++) {
arg_check = parse_args(argv);
if (arg_check == 1)
printf("Error: %s is an unknown command.", argv);
}
return 0;
}
int parse_args(char cmd_arg[])
{
switch(cmd_arg) {
case 'test1':
printf("%s\n", cmd_arg);
return 0;
case 'test2':
printf("%s\n", cmd_arg);
return 0;
default:
return 1;
}
}
-------------
When I try to compile this i get these errors:
$ gcc -Wall test.c -o test
test.c: In function `parse_args':
test.c:22: switch quantity not an integer
test.c:23: character constant too long
test.c:26: character constant too long
test.c:24: warning: unreachable code at beginning of switch statement
$
I think it all depends on the fact that I don't know how to format the code
correctly when handling arrays (Where to use "array[]", "array[x]" or
"array"). I think I can recall having problems with the same thing a year
ago when giving C++ a go. What am I doing wrong?
I think you'll understand the programs purpose, so I won't have to explain
it.