Marcos Marcos - 6 months ago 66
C Question

Using argv and strcmp at C

Im having some problem to use the strcmp function. Everytime I run this code, it just print the ERROR mensage, even if i use the correct argument at prompt.

if (strcmp(argv[1], "\?") == 0) {
}else {
printf ("ERROR.\n\n");

Can someone help me?


The \ character is used to begin an escape code in C strings. For example, \n denotes a newline.

Since \? is not a valid escape code, the backslash character is ignored. So the resulting string in the code is actually "?".

If you want you string to contain a literal backslash, use two backslashes.

if (strcmp(argv[1], "\\?") == 0) {