|
From: Johannes P. <joh...@pr...> - 2001-09-03 13:14:37
|
this here is a simple example that will make more sense. For considering
that you are trying to mix
your WINAPI functions and write to the handle of the file allocators. I do
not think that it is possible in
the compiler version. Maybe with a Microsft compiler.
else this is a VERY simple way to do it that works. I hope this help.,
Please mail if I misunderstand you.
//====== SNIP =========
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
struct test{
char data [200];
}testdata;
void main(void){
char outstring[200];
FILE *fhandle;
int actualnumber;
//open in write mode (override if exist);
fhandle = fopen("c:\\medcelldata.txt","w");
/*CreateFile("c:/medcelldata.txt",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
*/
if(fhandle == NULL)
{
printf("\nNO File present");
}
//copy test to structuer
strcpy(testdata.data,"Hallo World\n");
actualnumber = 1000;
//write using fwrite (BETTER for Structures)
fwrite(&testdata, sizeof(testdata), 1, fhandle);
//convert integer
itoa(actualnumber, outstring, 10);
//write with fprintf to file
fprintf(fhandle,"OutString : %s",outstring);
//clsoe file
fclose(fhandle);
}
//========= END SNIP =========
Hope it helps
Johannes
At 14:03 03/09/2001 +0200, you wrote:
>On 3 Sep 2001, at 11:57, Johannes Pretorius wrote:
>
> > Johannes Pretorius <joh...@pr...>
>
>
>Here it is ! i allready change something to make it run - but in the
>written file there only occurs 1- or two figures !
>
>How can i use the fprintf - function to access the file ????
>
>
>
>#include <iostream.h>
>#include <stdio.h>
>#include <stdlib.h>
>#include <windows.h>
>
>// vars
>
>HANDLE hcom; // file handler
>HANDLE hfile;
>DWORD dwWritten;
>
>int value[8];
>int numofdata[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
>
>BYTE noise; // for testing only
>BYTE activeitem; // no of active row
>
>BYTE in_buffer[35]; // input buffer = 8 needed
>BYTE out_buffer[35]; // output buffer
>
>int writepoint;
>int readpoint;
>int writepointin; // write pos inbuffer
>int readpointin; // read pos inbuffer
>int goodvalue;
>int tempvalue;
>int actualnumber;
>
>BYTE input;
>BYTE count;
>int globalschleife;
>LPTSTR lpMessage;
>
>int progmode; // bin or asc
>
>
>....
>
> hfile = CreateFile("E:/medcelldata.txt",
> GENERIC_READ | GENERIC_WRITE,
> 0,
> NULL,
> OPEN_ALWAYS,
> FILE_ATTRIBUTE_NORMAL,
> NULL
> );
>
> if(hfile == INVALID_HANDLE_VALUE)
> {
> printf("\nNO File present");
> }
>
> pstr = "MedCellCom 1.2\n\n ";
> WriteFile(hfile, pstr, 16, &dwWritten, NULL);
>
>
> pstr = "Prozess - Protokoll vom : \n ";
>
> WriteFile(hfile, pstr, 27, &dwWritten, NULL);
>
>
> itoa(actualnumber, outstring, 10);
>
> WriteFile(hfile, outstring, 10, &dwWritten, NULL);
>
> WriteFile(hfile, "456", 3, &dwWritten, NULL);
>
> printf("%d\t", dwWritten);
> printf("%s\n", outstring);
>
>
>
>The output shows only
>
> MedCellCom 1.2
>
> Prozess - Protokoll vom :
>2
>
>Where "2" ist the actualnumber
>
>I do not see the 456 test string allthoug the screen
>shows the correct outstring and 3 chars written !
>
>It is a big loop, where many lines are written and
>shown on the screeen it works and the prog terminates.
>
>When writing only dummy strings like explicit
>"iugnuztf" it works and show 200 lines with exactly
>this text !
>
>????
|