编辑代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
    FILE *fp;  //定义一个指针指向文件地址
    char str[3][10];
    int i;
    if((fp = fopen("E:string.dat","r"))==NULL)
    
    //利用fopen()函数打开文件 "r" "r+" "w" "w+"
    //读取成功返回1,失败返回NULL
    
        {
        printf("cannot open file\n");
        exit(0);
    }
    while(fgets(str[i],10,fp)!=NULL)
    {
        printf("%s",str[i]);
        i++;
    }
    fclose(fp);
    return 0;
}