Sunday, 15 January 2012

c - Open a file using fgets result doesn't work -



c - Open a file using fgets result doesn't work -

i'm trying open files using open(). file names stored in temporary file (one filename in each row). code i'm using:

char strbuf[64]; while (fgets (strbuf, sizeof(strbuf), temp)) { printf("%s\n", strbuf); if((txt_fd = open(strbuf, o_rdwr | o_append)) < 0) { printf("open error!\n"); exit(1); } }

and output:

data1.txt open error!

the weird thing if manually set open() way open() works.

txt_fd = open("data1.txt", o_rdwr | o_append)

what's wrong strbuf?

thanks in advance.

c file char system-calls fgets

No comments:

Post a Comment