| | |
Image read and write operations in turbo C
![]() |
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 <stdio.h> /* 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]
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 <stdio.h> /* 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]
May 'the Google' be with you!
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
thanks a lot vegaseat..
ur code is working great..
i am actually reading a gray scale image, which has 0-255 levels of gray intensities.
so each pixel in the image or each character represents a level of gray intensity(eight bits in binary).
but as far as characters are concerned, there are only 128 ascii chars, so how can 128 ascii chars represent 256 levels of image intensities??
guess i made my question clear enough..
can anyone clear it for me???
ur code is working great..
i am actually reading a gray scale image, which has 0-255 levels of gray intensities.
so each pixel in the image or each character represents a level of gray intensity(eight bits in binary).
but as far as characters are concerned, there are only 128 ascii chars, so how can 128 ascii chars represent 256 levels of image intensities??
guess i made my question clear enough..
can anyone clear it for me???
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by frrossk
In fact, 1 byte = 8 bits; so a char variable can have 2^8 = 256 values; this have nothing to do with ASCII chars...
i am reading the file in turbo C in an 2d char array and comparing with another similar picture to check if they are the same..
and i am doing some enhancement of the original image,
and to view the enhanced image, am changing .dat to .raw format and viewing in adobe photoshop.
well is this process right?
in the sense that getting an gray scale image in 2d char array.
will it be exactly reproduced.
will the 2d char array handle a gray scale image?
thats my basic doubt..
![]() |
Other Threads in the C Forum
- Previous Thread: Reading from a floppy disk
- Next Thread: Programming Problem Help for school
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






