473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

fread/fwrite

PLEASE DO NOT BE INTIMIDATED BY THE SIZE OF MY CODE, I BELIEVE THE PROBLEM IS VERY SIMPLE AND IT IS MARKED WITH /*ERROR*/. when i run the exe, i can add 2 patients easily to the file. then i try to display them. it displays the first one just fine, but the second it tries to display the first value in the [1]th element of the array, i get an error message. that part of my code is marked with a /*ERROR*/ just before it. easy to find plz help this is due monday. if u can solve my problem then just give me a jpeg and will erect a 500 meter idol of worship in your image.

file attached has code
Attached Files
File Type: txt code.txt (13.7 KB, 407 views)
May 10 '08 #1
9 1368
y cant i see my own post?
May 10 '08 #2
Niheel
2,460 Expert Mod 2GB
fixed, your code caused a bug to show up. fixed it by uploading as attachment.
May 10 '08 #3
ok there it is... dont know wny it was invisible b4...
can u help me out? i would be eternally greatful
May 10 '08 #4
lol i started the post before u posted lol
May 10 '08 #5
oler1s
671 Expert 512MB
Learn to be able to identify the problematic portions in your code, and attempt to fix them. So your program has a bug. It's called programming. Now try and fix it.

If you know the problematic portion of your code, post only that portion. Indicate detailed observations. What do you expect your code to do? When testing that portion of the code, what input did you give. What output did you get. What is the error message you get? What did you find with a debugger? That sort of thing.
May 11 '08 #6
yo someone just gave me a hint but they were a little unspecific, he said "it probably didnt clean the buffer between READING the 1st file and inputing the SECOND file"
so how do i do that? FFLUSH(STDIN);? system("cls");?
May 11 '08 #7
oler1s
671 Expert 512MB
I just took a look at your code, and it's a downright mess. It's questionable how you came up with this code. Interesting things to note: your use of #include "iostream" and "stdio.h" and "string.h" and "process.h" (?). Clearly, you aren't even familiar with how to do the most basic, which is even include standard headers. How did you get your code to compile? Why do you rely on process.h?

Why are you using the C I/O if you have access to C++ I/O?
Why are you not using C++ strings?

Your code is buggy in several areas. You should not use fflush(stdin). fflush is only defined to work on output streams, not input. If fflush(stdin) works for you, it's because your compiler supports a non-standard extension. Guess what, it might not work on your teacher's computer.

You can't tell whether you hit an EOF, until you actually try to read. After you attempt a read, it either works, or it fails partially or completely. You have somewhere in your code while (!feof). But wait a minute, there is no way to know if your next read will fail on EOF. So guess what, you need to read the documentation for feof. It does not do what you think it does.

You use several non standard functions, which you shouldn't do as a beginner. What's funny is your use of gets_s. Use fgets, not gets. gets is marked off in all documentation as do not use.

Your code is a horrible horrible, poorly formatted, mess. The questions you ask and the way your code is written suggest you don't really know what you're doing, and are trying to slap together code that can fly by your teacher. Maybe I'm horribly wrong, but the fact that you have more fundamental issues with your code, like, it's C code with C++ headers, and so on, suggest, a number of things.

If you really want help, start by rewriting decent code. EDIT: Notably, you may want to (a) decide whether you want to use C or C++ and (b) read a book or tutorial on how to write in said language. Hint: Getting your headers in order might be a good start.
May 11 '08 #8
its also interesting that "numread" returns a zero on the first patient and a 1 on the 2nd patient
May 11 '08 #9
oler1s
671 Expert 512MB
its also interesting that "numread" returns a zero on the first patient and a 1 on the 2nd patient
numread has the return value for the fread function. What does this return value indicate?
May 11 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Brady | last post by:
Hi, I'm having a problem reading and writing to a file. What I'm trying to do is read a file, modify the portion of the file that I just read, and then write the modified data back to the same...
2
by: Luc Holland | last post by:
Hey, I'm working on a program that reads a binary file. It's opened with ==== if ((f1=fopen(argv,"rb"))==NULL) { fprintf(stderr,"Error opening %s for reading . . .\n",argv); exit(2); } ====...
4
by: janssenssimon | last post by:
//de structure om de highscores in op de slagen typedef struct score{ char *naam; int veld; int score; struct score *volg; }HIGH; void toonhighscores(void)
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
2
by: elisa | last post by:
Dear all, I have problems in writeing and reading a block of data (long array) with fread and fwrite. If I write and read an integer array, everything looks fine, but when I try long array, sth...
1
by: rohit deshpande | last post by:
i am writing a program in c,c++....... I want to read one file and write its contents using fread and fwrite functions. the program i hv written has no errors. but output file is not same as that of...
5
by: loudking | last post by:
Dear all, I encountered a problem with fread and fwrite. If I am going to copy a file using the same string, it will succeed char *file_content; struct stat buf; FILE *fp, *new_fp; ...
30
by: empriser | last post by:
How to use fread/fwrite copy a file. When reach file's end, fread return 0, I don't konw how many bytes in buf.
4
by: Highlander2nd | last post by:
Hello there. I'm Andrew Lucas, I'm a programmer for Half-Life. I've been working on stencil shadows lately, and I've been having problems saving mesh data for my models. When I store mesh data, I...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.