![]() |
Problem with opening a file
Hi
I am a beginer to C Programming.I was trying to open a .txt file for reading but couldnt do that this is my code..Help me out. :
#include<stdio.h> |
What do you mean "couldnt do that"? Your code looks like it should work.
|
This won't fix whatever problem you are having, but make that
int main () and return 0 ; at the end. DaWei said that on here once, so do it! Lol. this might fix your problem: Your code looks like it should work to me. You might consider that you won't be able to open a file for reading if that file doesn't exist. I'm not sure if that is the case (it might create a blank file called raghu.txt), but in any case, you shouldn't try to read from a file that doesn't exist. So look in your directory and make sure that there is a file in that directory called raghu.txt . Also, you made a call to fprintf, and sent the output to "fp". However, fp was used for reading, not for writing. You are trying to write to a file that is open for reading. This will yield unexpected results, I would imagine. If you want to open for reading and writing, use r+ instead. |
Post any errors that your compiler shows, if there is any. Maybe the conio.h doesn`t support the clrscr() function.
|
open the file in write mode.
|
cheap freelancer, please review the forum's rules regarding commercial signatures.
|
Quote:
@OP: please post any errors that you encounter while compiling, as mentioned earlier. |
Quote:
|
You need to decide if you're trying to read from a file, write to a file, or both. As it stands, you're opening the file in read mode:
:
fp=fopen("raghu.txt","r");:
fprintf(fp,"\n HI");You might want to check this reference if you don't have documentation for the C standard library. It doesn't have everything, but it's got the essential stuff for C and C++. |
| All times are GMT -5. The time now is 2:37 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC