1
嗨我對C很新,我想在C中做一個調查程序,允許用戶在不同類型的問題之間作出選擇並將調查存儲在一個文件中。我的代碼不會在while循環中輸入並在它之前終止。有人可以指出錯誤嗎?C調查程序
makesurvey()
{
int tfquestions, mcq, shortq,essayq,rankq ;
int i=1;
char *buffer;
printf("\nEnter the number of True/False Questions, Multiple Choice, Short answer , EssayAnswer and rank the choice questions ");
scanf("%d",&tfquestions);
scanf("%d",&mcq);
scanf("%d",&shortq);
scanf("%d",&essayq);
scanf("%d",&rankq);
FILE *fp;
fp = fopen("survey.txt","w");
while(i=!tfquestions)
{
if(fp != NULL)
{
fprintf(fp,"Enter The True false question");
buffer = (char*)malloc(sizeof(40));
fscanf(fp,"%c",buffer);
fclose(fp);
}
else
{
printf("Could not open the file");
}
i++;
}
'(I =!tfquestions)'表示 「分配'未tfquestions'(0或1)以'i'」 – pmg
'而(I =!tfquestions)'應該使用'!='。因爲你把'i'設置爲'!tfquestions',結果爲0. –
好吧謝謝(Y) – Pradit