| | |
please give me a simple file handling program
![]() |
•
•
Join Date: Jan 2008
Posts: 13
Reputation:
Solved Threads: 0
i need a sample program for handling text files using c language.. i don't know the syntaxes.. please help me and provide some comments on the source code so that i'll be on track..
Things that i need:
1) How to locate the text file
2) How to input values in that text file
3) How to read the texts in the text file
4) What are the things that i need to consider in creating the program
Thanks a lot...
Things that i need:
1) How to locate the text file
2) How to input values in that text file
3) How to read the texts in the text file
4) What are the things that i need to consider in creating the program
Thanks a lot...
>How to locate the text file
What do you mean by this? Do you mean "open" the file when you already know the name? Or are you searching for a text file on your hard drive?
>How to input values in that text file
>How to read the texts in the text file
http://www.cprogramming.com/tutorial/cfileio.html
>What are the things that i need to consider in creating the program
Make sure you don't use feof() to check if you're at the end of the file. See this explanation:
http://www.gidnetwork.com/b-58.html
What do you mean by this? Do you mean "open" the file when you already know the name? Or are you searching for a text file on your hard drive?
>How to input values in that text file
>How to read the texts in the text file
http://www.cprogramming.com/tutorial/cfileio.html
>What are the things that i need to consider in creating the program
Make sure you don't use feof() to check if you're at the end of the file. See this explanation:
http://www.gidnetwork.com/b-58.html
Last edited by John A; Feb 11th, 2008 at 9:56 pm. Reason: ack, I forgot this is C, not C++!
"Technological progress is like an axe in the hands of a pathological criminal."
the very basic basics of C file handling.
this will get you started.
remember you always need to #include <fileio.h>
c Syntax (Toggle Plain Text)
if ((fp = fopen(filename,"r"))==NULL) { printf("cannot open file `%s`\n",filename); exit (1); } while (fgets(buf,80,fp)) // this assumes text lines are less than 80 chars! { if (strstr(buf,"waldo") != NULL) { printf("found him!"); waldo++; } printf("I found waldo on %d lines.\n",waldo); } fclose (fp);
this will get you started.
remember you always need to #include <fileio.h>
Last edited by jephthah; Feb 12th, 2008 at 1:57 am.
•
•
•
•
oops, yeah. thanks
and i also meant to put the last "printf" statement *AFTER* the close of the while() block.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
well I am new here .... but I didn't think the purpose of this site is to supply completely error-free and 100% syntactically-correct source code for people to cut-and-paste. thats what homework services do. im just giving ideas and a framework of code fragments on how to solve the problem.
anyhow, there's got to be some amount of effort and initiative to solve problems here. amirite?
anyhow, there's got to be some amount of effort and initiative to solve problems here. amirite?
Last edited by jephthah; Feb 12th, 2008 at 1:19 pm.
So? Isn't it obvious even to someone new you don't want to answer a question with invalid advice?
You are absolutely correct. But if the small snippets of code you post are filled with errors in syntax and/or logic, how have you really helped someone? They get confused, then post "I don't understand why your advice didn't work!", then you have to apologize and correct your post. They've lost a day because of an invalid code snippet. That's what I'm saying. So try to verify before you post, that's all.
And of course errors slip in. But fewer will by testing/proofreading.
•
•
•
•
but I didn't think the purpose of this site is to supply completely error-free and 100% syntactically-correct source code for people to cut-and-paste. thats what homework services do. im just giving ideas and a framework of code fragments on how to solve the problem.
anyhow, there's got to be some amount of effort and initiative to solve problems here. amirite?
And of course errors slip in. But fewer will by testing/proofreading.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
"filled with errors" ??
step off my grill, dog. the code snippet -- as it is written -- *works* and it is entirely suitable for someone wanting code handed to them.
now tell me, do you always engage in such tendentious pedantry on trivial matters, or do you reserve this unappealing behavior only for the new people?
:roll:
step off my grill, dog. the code snippet -- as it is written -- *works* and it is entirely suitable for someone wanting code handed to them.
now tell me, do you always engage in such tendentious pedantry on trivial matters, or do you reserve this unappealing behavior only for the new people?
:roll:
Last edited by jephthah; Feb 12th, 2008 at 3:27 pm.
![]() |
Similar Threads
- Winsock Multi-Client Servers (C++)
- fstream Tutorial (C++)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Open In New Window Php (PHP)
- New proggrammer need tips (Game Development)
Other Threads in the C Forum
- Previous Thread: need help with c please
- Next Thread: Octal to Decimal number conversion program
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






