Warning: comparison with string literals results in unspecified behaviour

后端 未结 7 2377
终归单人心
终归单人心 2020-12-05 01:52

I am starting a project of writing a simplified shell for linux in C. I am not at all proficient with C nor with Linux that\'s exactly the reason I decided it would be a goo

相关标签:
7条回答
  • 2020-12-05 02:45
    if (args[i] == "&")
    

    Ok, let's disect what this does.

    args is an array of pointers. So, here you are comparing args[i] (a pointer) to "&" (also a pointer). Well, the only way this will every be true is if somewhere you have args[i]="&" and even then, "&" is not guaranteed to point to the same place everywhere.

    I believe what you are actually looking for is either strcmp to compare the entire string or your wanting to do if (*args[i] == '&') to compare the first character of the args[i] string to the & character

    0 讨论(0)
提交回复
热议问题