[C] Can't print in screen the content of file
why this code can't print in the while loop the content of the file ?
Code:
#include <stdio.h> |
First off, your main problem lies here:
Code:
fp = fopen("testq.txt","w"); /* you're trying to read from a file that's open for writing __only__*/ Code:
fprintf(fp,"yoooo maybe this is a second line\n"); The third, major problem is your loop. It won't work correctly written this way. But I don't really want to spoon feed you here, take it for a spin, try to fix it and report back if needed, mkay? |
Change
Code:
fp = fopen("testq.txt", "w"); Code:
fp = fopen("testq.txt", "r+"); |
so.. the file testq.txt has chmod 777 so the prog can write to it.
i run cat testq.txt and take back what i want yooo i can write in you yoooo maybe this is a second line The problem is why the program doesn't prints the content of this file.. @Maligree : Maybe the prob is in loop as you said.. How about to use feof() @smeezekitty : Why to do something like that ? And if i do it still doesn't work.. |
Quote:
|
You're confusing filesystem permissions with those used when opening a file. You're opening it with the "w" flag set - this means "try to open this file for writing only", no matter what the filesystem permissions are.
Screw it, I'm in a good mood today. Take a look: Code:
#include <stdio.h> |
Ok thanks a lot i'll see it..
|
Quote:
|
All times are GMT -5. The time now is 07:58 AM. |