简体   繁体   中英

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) {
    ajudaPrompt();
}else {
    printf ("ERROR.\n\n");
    system("pause");
}

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) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM