•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,582 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1250 | Replies: 10 | Solved
![]() |
| |
Simple file io. First hit on google - http://www.cprogramming.com/tutorial/cfileio.html. All you need to do is point the file pointer to your desktop. You can hard code that if you want. Then open the file for reading (see link), and print its contents to screen.
Last edited by twomers : Nov 3rd, 2007 at 8:36 am.
•
•
Join Date: Oct 2007
Posts: 20
Reputation:
Rep Power: 0
Solved Threads: 0
i tried to create a simple test program bu it could not print the contents of the file myfile.txt.
please help!
Regards
Prashant
please help!
c Syntax (Toggle Plain Text)
#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
Last edited by WaltP : Nov 3rd, 2007 at 1:54 pm. Reason: Removed unnecessary color and Added CODE tags -- you actually typed right over how to use them when you entered this post...
Do you want to print the contents to your screen or to the file? The way you opened the file there was for writing, that's what the w stands for. I was under the impression that you wanted to read the file. Use r for that. Look into fgets, or fscanf (if memory serves). http://www.cplusplus.com/reference/c...dio/fgets.html
•
•
Join Date: Oct 2007
Posts: 20
Reputation:
Rep Power: 0
Solved Threads: 0
I want to print the contents on screen and I also tried with "r" instead of "w" but it is not working!!
c Syntax (Toggle Plain Text)
#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(); }
Last edited by WaltP : Nov 3rd, 2007 at 1:52 pm. Reason: Removed unnecessary color and Added CODE tags -- you actually typed right over how to use them when you entered this post...
Regards
Prashant
Prashant
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
•
•
Join Date: Oct 2007
Posts: 20
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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.
Regards
Prashant
Prashant
•
•
•
•
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...
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- ifstream help? (C++)
- Importing SQL Script File - Urgent !! (Database Design)
- Syntax for deleting specified file ( in C++) (C++)
- enabling file sharing (Windows NT / 2000 / XP / 2003)
- data file help (C)
- connect to text file database (Visual Basic 4 / 5 / 6)
- 81TB File Server (Networking Hardware Configuration)
Other Threads in the C Forum
- Previous Thread: Determining Invalid Characters in a String??
- Next Thread: Search function in textfile?



Hybrid Mode