Click to See Complete Forum and Search --> : c problem


monkeyboi
08-25-2002, 12:13 AM
i wrote a small factor program (i kno they already have one came with most distro from GNU)

anyway my problem is i can't get my text argument to work here is an example..

#include <stdio.h>

main(int argc, char *argv[])

{
if (argv[1] == "test")
{
printf("working!");
}
else
{
printf("not working!");
}
}

ok i compiled and enter
user$ c test
not working!
user$

y is that?? shouldn't it be working cuz the test is the same...

it works fine for number when i use atoi() function to convert the argv string into integer. but the argv is already char data type....
any1 have any idea how fix this or is there is string converter like atoi() for integer???

thx!

chris_i386
08-25-2002, 12:32 AM
You can't compare strings like
if (string1 == string2) ...

You have to use
if ( ! strcmp(string1, string2)) ...

strcmp() returns 0 if both strings are equal.

There are good C tutorials on the net, maybe think of buying 'The C Bible':
The C Programming Language, Second Edition, by Kernighan & Ritchie

mingshun
08-25-2002, 04:20 AM
is there is string converter like atoi() for integer???


sprintf