I want to open a text file in a c program which is on desktop.How can I print the texts written in the file on screen.Please help


Regards
Prashant

i tried to create a simple test program bu it could not print the contents of the file myfile.txt.
please help!

#include<stdio.h>
int main()
{
    FILE *fp;
    fp=fopen("C:\\Documents and Settings\\Administrator\\Desktop\\myfile.txt", "w");
    fprintf(fp, "Testing...\n");
    getch();
}

Regards
Prashant

I want to print the contents on screen and I also tried with "r" instead of "w" but it is not working!!

#include<stdio.h>
#include<conio.h>
int main()
{
    FILE *fp;
    fp=fopen("C:\\Documents and Settings\\Administrator\\Desktop\\myfile.txt", "r");
    fprintf(fp, "Testing...\n");
    getch();
}

It would be far more useful if you experimented with the code tags as opposed to the colour tags.

can u help me what I am doing wrong in above program??

Yes, read the link you were given twice. It tells you how to do what you want. If not, ask a specific question.

Yes, read the link you were given twice. It tells you how to do what you want. If not, ask a specific question.

my question is should I give the full path name as C :\\Documents and Settings\\Administrator\\Desktop\\myfile.txt in the as fopen("C:\\Documents and Settings\\Administrator\\Desktop\\myfile.txt", "r") function or should I give only fopen ("myfile.txt" , "r") in order to open a file from desktop and display its content on screen.

my question is should I give the full path name as C :\\Documents and Settings\\Administrator\\Desktop\\myfile.txt in the as fopen("C:\\Documents and Settings\\Administrator\\Desktop\\myfile.txt", "r") function or should I give only fopen ("myfile.txt" , "r") in order to open a file from desktop and display its content on screen.

Then that's what you should ask.

Use the full path...

This question has already been answered. Start a new discussion instead.