how to open file using c program?

Re: open file using c 80 80

freopen() OR fopen(). try to read about them, you will find them useful. thanks.

Re: open file using c 80 80

Use fopen

Re: open file using c 80 80
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("c:\\1.txt","r+");
return 0;
}

its not working..plz help..

Re: open file using c 80 80

How can you tell that program isn't working since it doesn't actually have any output?

Re: open file using c 80 80

In order to know if it worked or not you have to test the return value of fopen()

#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("c:\\1.txt","r+");
if( fp == NULL)
   printf("file not found\n");
else
   printf("Success!\n");
fclose(fp);   
return 0;
}
Re: open file using c 80 80

using this code its only print success..
i want to display file in notepad..

Re: open file using c 80 80

using this code its only print success..

That's the point of the program, to tell you whether the file was opened successfully.

i want to display file in notepad..

Please note that we're not going to write your program for you. You asked a specific question and got a specific answer. Now it's up to you to ask more specific questions or apply what you've learned in this thread to your actual program.

Re: open file using c 80 80

You asked the wrong question at the beginning of this thread. Why didn't you say that in the first place, we can't read your mind. You need to use this function to launch Notepad.exe

Re: open file using c 80 80

thanx.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.