我是C程序設計新手。你能告訴我,我的代碼有什麼問題嗎?它看起來像if
聲明不起作用,而是跳轉並打印else
聲明。所有的if語句不起作用的字符串比較
#include <stdio.h>
#include <stdlib.h>
int main()
{
char profession;
printf("what is your profession? \n");
scanf(" %s", profession);
if(profession==「QA」)
{
printf(「Go and Test\n「);
}
else
{
printf("Do whatever you want");
}
return 0;
}
不能 - 不能比較這樣的以null結尾的char數組。這也是一個多重複制。 –
我仍然困惑。像我應該在哪裏做出改變? – Sus
你有多個錯誤,顯示一些錯覺。你的編譯器應該已經警告(如果沒有,啓用警告)。請閱讀關於指針,數組和字符串的C書(以及其他)。 – Olaf