reading a string from a file

前端 未结 4 631
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:35

    Use fgets to read string from files in C.

    Something like:

    #include 
    
    #define BUZZ_SIZE 1024
    
    int main(int argc, char **argv)
    {
        char buff[BUZZ_SIZE];
        FILE *f = fopen("f.txt", "r");
        fgets(buff, BUZZ_SIZE, f);
        printf("String read: %s\n", buff);
        fclose(f);
        return 0;
    }
    

    Security checks avoided for simplicity.

提交回复
热议问题