Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a string from a file

Tags:

c

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

like image 302
user556761 Avatar asked Nov 28 '22 15:11

user556761


1 Answers

Use fgets to read string from files in C.

Something like:

#include <stdio.h>

#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.

like image 172
Pablo Santa Cruz Avatar answered Dec 18 '22 07:12

Pablo Santa Cruz