Warning: comparison with string literals results in unspecified behaviour

后端 未结 7 2435
终归单人心
终归单人心 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:37

    You want to use strcmp() == 0 to compare strings instead of a simple ==, which will just compare if the pointers are the same (which they won't be in this case).

    args[i] is a pointer to a string (a pointer to an array of chars null terminated), as is "&" or "<".

    The expression argc[i] == "&" checks if the two pointers are the same (point to the same memory location).

    The expression strcmp( argc[i], "&") == 0 will check if the contents of the two strings are the same.

提交回复
热议问题