My notes on FILES in C

Reading File Line by line:

FILE *fp  = fopen("filename", "r");
char buf[512];
while(fgets(buf, 512, fp)!=NULL) {
    puts(buf);
}
fclose(fp);

Reading File Character by Character:

FILE *fp  = fopen("filename", "r");
int ch;

while((ch = fgetc(fp))!=EOF) {
    putchar(ch);
}
fclose(fp);

Random Access :

ftell(fp) returns the offset of the File
The  rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file.

              (void) fseek(stream, 0L, SEEK_SET)

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig