Turbo C?
I didn't know anybody still used this old horse!
Anyway, I found something in my archives and removed the dust! This reads a character file, you want to read a binary file. The end of file marker will be different. Well partner, it's a start!
[PHP]/******************************* fgetc.c ********************************
**
** Experiments with disk file I/O:
** int fgetc(FILE *stream)
** Get a character from the device indicated by stream ( set by fopen() ).
** Written in Turbo C by vegaseat 6/23/88
**
****************************************************************************/
#include /* defines FILE and EOF */
#define AMOUNT 5 /* amount of data items */
#define FALSE 0
#define TRUE 1
int display_file(void);
void main(void)
{
if (display_file() == FALSE)
puts("\n Couldn't open data file!");
printf("\n\n Press any key to go on .... ");
getchar(); /* wait */
}
int display_file(void) /* read an ASCII file and display on screen */
{
int ch; /* use int since EOF = -1 */
char filename[25];
FILE *fptr;
clrscr();
printf("\n Enter name of ASCII file : ");
gets(filename);
fptr = fopen(filename,"r"); /* open file for disk reading */
if (fptr == 0)
return (FALSE); /* file opening unsuccessful */
while ((ch = fgetc(fptr)) != EOF) /* read entire file and display */
putch(ch); /* it on the screen */
fclose(fptr); /* don't forget to close the file! */
return (TRUE); /* file succesfully scanned */
}
[/PHP]
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
>Well partner, it's a start!
If by start you mean poor quality code that doesn't address the problem at all, yes.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
You got me stomped, which is easy to do.
Looking through the dusty old code I noticed that I assigned the incoming character to type integer to trap the End Of File marker (-1). It makes me suspicious that in Turbo C type char was unsigned 8bit (0 to 255).
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
will the above code work in dev C compiler?
who knows? this thread FOUR YEARS OLD and is about a Turbo C program that was probably 10 years old when the thread was written.Please also tell me how to capture ,store and read images using dev C. It is urgent
No it'snot urgent.
your lack of foresight in starting your homework assignments constitutes no urgency on our part to go dig through some crappy old TURBO C program.
look here, son, going through life stealing other peoples programs off the internet without any understanding of what you are doing is going to come back and bite you in the ass, and hard.
And I'm not going to be the one to give you rope to hang yourself with.
you need to define your own problem, start coding your own solution, and then --- when you get stuck --- start your own thread using coherent questions and posting your own code using [code] tags.
and if you're using Turbo C, which i fear that you are, do yourself and the rest of the world a favor, and throw that crap into your recycle bin and get a REAL compiler.
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
(1) i dont answer unsolicited PMs for programming help
(2) you didnt read my reply, did you? Because if you did, you would Start a new thread
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179