Computer Science Canada I need help with file handling??? |
Author: | programming.noob [ Sat Jun 10, 2006 11:22 am ] |
Post subject: | I need help with file handling??? |
FILE *fptr; int num; fptr=fopen ("bankdatabase.txt","r"); fscanf (fptr,"%d",&num); ***how do i output the file into the C++ window*** |
Author: | wtd [ Sat Jun 10, 2006 11:27 am ] |
Post subject: | |
You should be aware that this is C code that you're dealing with, rather than C++. There is no "C++ window". Are you talking about standard output? |
Author: | programming.noob [ Sat Jun 10, 2006 11:18 pm ] |
Post subject: | |
yes im talking about standard output, sorry im new to the C language. |
Author: | programming.noob [ Sat Jun 10, 2006 11:22 pm ] |
Post subject: | |
I dont think you are my personal google i just wanted to know how i woud go about outputting the contents of the file database.txt. Which function would be appropriate. |
Author: | wtd [ Sun Jun 11, 2006 7:09 am ] |
Post subject: | |
That's my signature. It gets attached to every message I post. That said, if you Google "c file handling" you will get a lot of very relevant pages. |
Author: | programming.noob [ Sun Jun 11, 2006 2:59 pm ] |
Post subject: | |
do i use fprintf, or fgets to ouput the contents from the notepad file? |
Author: | wtd [ Sun Jun 11, 2006 3:40 pm ] |
Post subject: | |
Don't think in terms of code specifics . Think in terms of breaking the problem down. You have the file open. What's the next thing you have to do? |
Author: | programming.noob [ Sun Jun 11, 2006 10:05 pm ] |
Post subject: | |
welll i know i have to read the file in however i dont know how to output the notepad file contents. |
Author: | programming.noob [ Sun Jun 11, 2006 10:07 pm ] |
Post subject: | |
Also what do i break the program down into.. steps... but how i dont understand. I just want to output the contents of the notepad file. I thought it was a one liner. |
Author: | wtd [ Sun Jun 11, 2006 10:45 pm ] |
Post subject: | |
No no. Break the problem down into simpler problems. At this stage of the game, we're not even concerned with the program. |
Author: | Martin [ Mon Jun 12, 2006 2:48 am ] |
Post subject: | |
As in, think of the steps to do this without the programming part first. Don't worry about the code, just the method. Write it out as a list in plain English - ie. 1. First, we have to do this 2. Then, we do this. ... |
Author: | programming.noob [ Mon Jun 12, 2006 12:07 pm ] |
Post subject: | |
Can somebody tell me what the problem is with the error : cannot convert FILE to char for arguement. How come i cant get this to work it just wont work. I planned it out and everythgin #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <time.h> int main () { char file [50]; FILE * pFile; pFile = fopen ("bankdatabase.txt","r"); if (pFile==NULL){ printf ("File read correctly but not displayed"); abort(); } for (int i=0;i<50;i++) fgets (file,50,FILE); fputs ("bankdatabase.txt",stdout); fclose (pFile); fflush (stdin); getchar(); return 0; } |
Author: | wtd [ Mon Jun 12, 2006 12:13 pm ] |
Post subject: | |
Not to sound harsh, but do you have the first clue how C works? |
Author: | programming.noob [ Mon Jun 12, 2006 4:22 pm ] |
Post subject: | |
i have a vague idea..could you explain what you mean. Also i believe thats why i would come here...for help? |
Author: | programming.noob [ Mon Jun 12, 2006 4:24 pm ] |
Post subject: | |
can someone tell me how to fix the error in this program there is always a conflict bw datatypes |
Author: | wtd [ Mon Jun 12, 2006 4:26 pm ] |
Post subject: | |
Yeah, and I'm not trying to sound harsh. but it really does help to get an understanding of the basic concepts before trying anything that makes use of those concepts. For instance, do you understand what those #include lines are doing? I ask because you have some that serve no purpose in your program. |
Author: | programming.noob [ Mon Jun 12, 2006 5:28 pm ] |
Post subject: | |
yes i think they are libraries.. pre preocessor directives |
Author: | programming.noob [ Mon Jun 12, 2006 5:29 pm ] |
Post subject: | |
the #include lines dont seem to be the obstacle for the compiler when i try to run it their is something it doesnt like about the conditions. int read () { char file [35]; FILE * pFile; pFile = fopen ("bankdatabase.txt","r"); if (pFile!=NULL) int a; a=pFile; puts ("bankdatabase.txt",pFile); printf ("%d",a) else printf ("File read correctly but not displayed"); i thought i did it right. Can you please tell me the logic i need to follow to fix this. |
Author: | programming.noob [ Mon Jun 12, 2006 5:31 pm ] |
Post subject: | |
what i sent you is a portion fo the program it is only the file read and output to the screen part the other 75% of the program is done its this i cant get. |
Author: | programming.noob [ Tue Jun 13, 2006 12:03 pm ] |
Post subject: | |
how would i use strcmp...string compare to compare two strings. One which i get from the user and the second to check the input from the user in the file. How would i do this using C code. |
Author: | wtd [ Tue Jun 13, 2006 12:33 pm ] |
Post subject: | |
http://www.cplusplus.com/ref/cstring/strcmp.html It's the first hit whe you Google "c strcmp". |
Author: | programming.noob [ Tue Jun 13, 2006 4:12 pm ] |
Post subject: | |
what can i do to ensure that the data from the file is read according to what the user enters. For e.g. if the user enters barry john then the line with details of barry john should be seen in the run window. |
Author: | wtd [ Tue Jun 13, 2006 4:39 pm ] |
Post subject: | |
You read the name the user is looking for. As you read each line in the file, you check to see if it starts with that name. If it does, you print that line. Otherwise you go to the next line. If no lines satisyf this criteria, then obviously the user needs to try a different name. |
Author: | programming.noob [ Tue Jun 13, 2006 6:35 pm ] |
Post subject: | |
How can i delete records from a file if i wanted to suppose delete a specific line with the name entered by the user. if user enters john barry then delete john barry information from the file. |
Author: | Martin [ Tue Jun 13, 2006 8:57 pm ] |
Post subject: | |
Slow down and take everything one step at a time, right from the beginning. Learn about the structure of a basic C program. Learn what everything means. Learn how to use for loops and if statements and blocks within C. Learn the basics of how pointers and variables work and then move on to file input and such. Your problem right now is that you don't understand C's syntax - you're trying to run before you've learnt how to walk. |
Author: | programming.noob [ Wed Jun 14, 2006 7:42 am ] |
Post subject: | |
ok |
Author: | programming.noob [ Wed Jun 14, 2006 7:44 am ] |
Post subject: | |
it may seem like that but i do know the syntax a basic program flow.. i just cant think because i get nervous that its not going to work and have issues debugging. |
Author: | Martin [ Thu Jun 15, 2006 12:10 am ] |
Post subject: | |
Well, first off, what compiler are you using? I would recommend you download and install Cygwin (assuming that you are on Windows). With the installer, you should get GCC (which is the GNU Compiler Collection, which includes a C compiler). And don't be scared to compile programs that you know won't work - it won't hurt your computer, and you'll gain a better understanding of the language by knowing both what works and what doesn't work. |