【C语言】文件读写失败,创建文件但不输出在屏幕上

来自谭浩强C语言第四版


```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    FILE *fp;
    char str[3][10],temp[10];
    int i,j,k,n=3;
    printf("enter the strings\n");
    for(i=0;i<n-1;i++)
    {
        gets(str[i]);
    }
    for(i=0;i<n-1;i++)
    {
        k=i;
        for(j=i+1;j<n;j++)
        {
            if(strcmp(str[k],str[i])>0) k=j;
            if(k!=i)
            {
                strcpy(temp,str[i]);
                strcpy(str[i],str[k]);
                strcpy(str[k],temp);
            }
        }
    }
    if(fp=fopen("X:\\c\\test1.txt","w")==NULL)
    {
        printf("can not open the file!\n");
        exit(0);
        
    }
    printf("\nThe new sequence is:\n");
    for(i=0;i<n;i++)
    {
        fputs(str[i],fp);
        fputs("\n",fp);//写一行输出一个换行符
    }
    return 0;
}

```

if(fp=fopen("X:\c\test1.txt","w")==NULL)
改为
if((fp=fopen("X:\c\test1.txt","w"))==NULL) //注意多个括号