Hi
here is what iam trying to do.
->Create a File using structures
And Iam doing that by
1)Populating the structres
2)Putting the structres in a file
But the problem for me is that iam having a stucture which is unsigned char and i have to put double digit in it.
Iam enclosing a sample program I tried to dowith the header file
Header.h
typedef unsigned char byte;
typedef struct
{
byte nTest[4];
byte fTest;
byte cTest;
}TEST_T;
include <iostream.h>
#include <stdio.h>
#include "St.h"
#include <string.h>
class CF
{
public:
void Write1(char *,int);
void PutIn();
};
main()
{
CF c;
c.PutIn();
}
void CF:
utIn()
{
// TEST_T TEST;
TEST_T * TEST = new TEST_T;
TEST->nTest[0]='1';
TEST->nTest[2]='2';
TEST->fTest=23;
TEST->cTest = 20;
Write1((char *)TEST,sizeof(TEST_T));
}
void CF::Write1(char *towrite,int nSize)
{
FILE *pFile;
if((pFile = fopen("Testotest","w"
) == NULL)
cout<<"Open failed"<<endl;
if ((fwrite(towrite,nSize,1,pFile)) < 0)
cout<<"Fwrite Failed"<<endl;
fclose(pFile);
FILE *pFile1;
if((pFile1 = fopen("Testotest","r"
) == NULL)
cout<<"Open failed"<<endl;
TEST_T TEST2;
size_t nSize1 = fread(&TEST2,sizeof(TEST2),1,pFile1);
cout<<"SIZE = "<<nSize1<<endl;
cout<<TEST2.nTest[0]<<endl;
cout<<TEST2.fTest<<endl;
cout<<"Ftest"<<TEST2.fTest<<endl;
fclose(pFile);
}
I am able to compile this program and also run it.The problem is that Iam not able to get the desired output in the file
Here are the list of problems
1)The assignment in PutIn( ) function fails as Iam assigning double digit to unsigned char.
2)The Read also fails in the Write1() function
Can somebody help me in solving this error.
here is what iam trying to do.
->Create a File using structures
And Iam doing that by
1)Populating the structres
2)Putting the structres in a file
But the problem for me is that iam having a stucture which is unsigned char and i have to put double digit in it.
Iam enclosing a sample program I tried to dowith the header file
Header.h
typedef unsigned char byte;
typedef struct
{
byte nTest[4];
byte fTest;
byte cTest;
}TEST_T;
include <iostream.h>
#include <stdio.h>
#include "St.h"
#include <string.h>
class CF
{
public:
void Write1(char *,int);
void PutIn();
};
main()
{
CF c;
c.PutIn();
}
void CF:
{
// TEST_T TEST;
TEST_T * TEST = new TEST_T;
TEST->nTest[0]='1';
TEST->nTest[2]='2';
TEST->fTest=23;
TEST->cTest = 20;
Write1((char *)TEST,sizeof(TEST_T));
}
void CF::Write1(char *towrite,int nSize)
{
FILE *pFile;
if((pFile = fopen("Testotest","w"
cout<<"Open failed"<<endl;
if ((fwrite(towrite,nSize,1,pFile)) < 0)
cout<<"Fwrite Failed"<<endl;
fclose(pFile);
FILE *pFile1;
if((pFile1 = fopen("Testotest","r"
cout<<"Open failed"<<endl;
TEST_T TEST2;
size_t nSize1 = fread(&TEST2,sizeof(TEST2),1,pFile1);
cout<<"SIZE = "<<nSize1<<endl;
cout<<TEST2.nTest[0]<<endl;
cout<<TEST2.fTest<<endl;
cout<<"Ftest"<<TEST2.fTest<<endl;
fclose(pFile);
}
I am able to compile this program and also run it.The problem is that Iam not able to get the desired output in the file
Here are the list of problems
1)The assignment in PutIn( ) function fails as Iam assigning double digit to unsigned char.
2)The Read also fails in the Write1() function
Can somebody help me in solving this error.