home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2001 December
/
pcwk12201b.iso
/
Reklamy
/
CAD-Projekt
/
MegaCAD-4_5
/
CC
/
DATEIEN.C_
/
DATEIEN.C
Wrap
C/C++ Source or Header
|
1995-03-21
|
4KB
|
127 lines
/**********************************************************************/
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0
#include "std.h"
#include "megatyp.h"
#include "megacad.h"
/**********************************************************************/
static short SeekMess(short cwritten,short pos,short fh)
{
long fpos;
char buf1[255];
if( ! cwritten)
{
fpos = ML_Tell(fh);
sprintf(buf1,"file position : %ld Pos %d",fpos,pos);
Message("ML_Seek OK",buf1,NULL,NULL,"OK",3);
return(FALSE);
}
else
{
sprintf(buf1,"file position : %ld Pos %d",fpos,pos);
Message("ML_Seek Error",buf1,NULL,NULL,"OK",3);
ML_Close(fh);
return(TRUE);
}
}
/**********************************************************************/
short main(
char *filename,
char *args )
{
short fh, cwritten;
long fpos;
uint uread;
char buf[51], buf1[51], *pbuf;
// open file for writing and reading in textmode
fh = ML_Open("dummy.txt",ML_WRITE | ML_PLUS | ML_TEXT);
// show handle number
sprintf(buf1,"%d",fh);
Message("Dateihandle :",buf1,NULL,NULL,"OK",3);
// write a text with ML_Puts
strcpy(buf,"Werner");
cwritten = ML_Puts(buf,fh);
sprintf(buf1,"written characters : %d",cwritten);
Message("ML_Puts",buf1,NULL,NULL,"OK",3);
// get file position with ML_Tell
fpos = ML_Tell(fh);
sprintf(buf1,"file position : %ld",fpos);
Message("ML_Tell",buf1,NULL,NULL,"OK",3);
// position filepointer on the start of file
ML_Rewind(fh);
fpos = ML_Tell(fh);
sprintf(buf1,"file position : %ld",fpos);
Message("ML_Rewind",buf1,NULL,NULL,"OK",3);
// read the written text with ML_Gets
pbuf = ML_Gets(buf,20,fh);
sprintf(buf1,"read : (%s) ret. Pointer : (%s)",buf,pbuf);
Message("ML_Gets",buf1,NULL,NULL,"OK",3);
// position filepointer 2 characters before the end of file
fpos = ML_Tell(fh);
sprintf(buf1,"file position before ML_Seek : %ld",fpos);
Message("ML_Seek",buf1,NULL,NULL,"OK",3);
cwritten = ML_Seek(fh,(-2L),SEEK_END);
if(SeekMess(cwritten,1,fh))
return;
// move filepointer to the end of file
cwritten = ML_Seek(fh,(0L),SEEK_END);
if(SeekMess(cwritten,2,fh))
return;
// write one character with ML_Putc
cwritten = ML_Putc(fh,'a');
sprintf(buf1,"'a' written ret.character : %c",cwritten);
Message("ML_Putc",buf1,NULL,NULL,"OK",3);
// read the first character of the file with ML_Getc
ML_Rewind(fh);
cwritten = ML_Getc(fh);
sprintf(buf1,"character must be 'W'. ret. character : %c",cwritten);
Message("ML_Getc",buf1,NULL,NULL,"OK",3);
// move filepointer to the end of file
cwritten = ML_Seek(fh,(0L),SEEK_END);
if(SeekMess(cwritten,3,fh))
return;
fpos = ML_Tell(fh);
// write a 10 character long string with ML_Write
strcpy(buf,"HUGOvomORT");
cwritten = ML_Write(buf,10,fh);
sprintf(buf1,"%s written. written char.: %d",buf,cwritten);
Message("ML_Write",buf1,NULL,NULL,"OK",3);
// move filepointer to the start of file
cwritten = ML_Seek(fh,fpos,SEEK_SET);
if(SeekMess(0,4,fh))
return;
// read the text with ML_Read but only 8 characters
cwritten = ML_Read(buf,8,fh);
buf[cwritten] = '\0'; // NULL terminate, ML_Read does not do it !!!
sprintf(buf1,"Text :[%s] ret:(%d)",buf,cwritten);
Message("ML_Read",buf1,NULL,NULL,"OK",3);
// move filepointer to the end of file
cwritten = ML_Seek(fh,(0L),SEEK_END);
if(SeekMess(cwritten,5,fh))
return;
// write the current fileposition with ML_Printf
ML_Printf(fh,"%s : %ld","cur.position",ML_Tell(fh));
// close file
ML_Close(fh);
}
/**********************************************************************/