[英]Operator == doesn't work in C
用C編寫程序時出現奇怪的錯誤。
這是我的代碼:
#include <stdio.h>
#include <stdlib.h>
#include "defs.h"
int main (int argc, char* argv[])
{
int boardSize = atoi(argv[2]);
int generations = atoi(argv[4]);
int gamesort = atoi(argv[1]);
printf("2 is %d 1 is %d 4 is %d name of file is %s \n",boardSize,gamesort,generations,argv[3]);
if (1==1)
{
printf("yes");
ZeroPlayersGame(boardSize, generations,argv[3]);
}
else//(gamesort==2)
{
TwoPlayersGame(boardSize, generations,argv[3]);
}
return 0;
}
這是我從終端獲得的錯誤:
ise@ubuntu:~/Desktop$ make
gcc -c main.c defs.c gameIO.c zeroPlayer.c twoPlayer.c
gcc gameIO.o defs.o zeroPlayer.o main.o twoPlayer.o -o prog
ise@ubuntu:~/Desktop$ ./prog 1 2 "l.txt" 3
2 is 2 1 is 1 4 is 3 name of file is l.txt
Segmentation fault (core dumped)
很奇怪,您可以看到我的程序沒有輸入我的第一個“ if”,但是您可以看到它在if語句之前打印了一行。
謝謝你的幫助!
我認為您的問題與您的問題標題“運算符==在C中不起作用”無關。 從輸出中可以看出,printf可以正常工作,並且函數“ ZeroPlayersGame”和“ TwoPlayersGame”中可能存在問題。 如果您向我們提供了有關這兩個功能的更多信息,則解決問題將變得更加容易。 另外,在邏輯語句中使用“ 1 == 1”也很奇怪。 為什么不消除它,並在printf語句之后編寫您的語句。 因為“ 1 == 1”始終為真。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.