C调查计划

时间:2013-04-02 17:46:36

标签: c file-io

您好我是C的新手,我正在尝试在C中制作一个调查程序,允许用户在不同类型的问题之间做出选择,并将调查存储在一个文件中。我的代码没有进入while循环并在它之前终止。有人可以指出错误吗?

 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++;
    }

1 个答案:

答案 0 :(得分:4)

你需要使用!= bot =!

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++;
}