reading a string from a file

前端 未结 4 621
Happy的楠姐
Happy的楠姐 2021-01-06 04:03

I have one text file. I have to read one string from the text file. I am using c code. can any body help ?

4条回答
  •  执笔经年
    2021-01-06 04:38

    This is a Simple way to get the string from file.

    #include
    #include
    #define SIZE 2048
    int main(){
    char read_el[SIZE];
    FILE *fp=fopen("Sample.txt", "r");
    
    if(fp == NULL){
        printf("File Opening Error!!");
    
    }
    while (fgets(read_el, SIZE, fp) != NULL)
        printf(" %s ", read_el);
    fclose(fp);
    return 0;
    }
    

提交回复
热议问题