hello again
g++ 3.3.6 compiler on slackware linux but
i am using the qmake utility of QtDesigner to generate the makefile,
then i just type make...
still no qlibraries are used in this part of the program...
here im sending u the fileIO.h and fileIO.cpp as well as a globalVars.h
and a main.cpp that i made to test the fileIO files:
/*------------globalVars.h----------------------------------------------------------*/
#ifndef GLOBALVARS_H
#define GLOBALVARS_H
int appDateTimeOffset;
unsigned char operationalState; //0=auto, 1=manual,
2=scheduled, 3=logging
unsigned char logSamplingPeriod; //0=off, 1=1min, 2=10min,
3=30min, 4=1hour
unsigned char logType; //0=cyclical, 1=linear
unsigned char changeLog; //0=per1min, 1=per1hour,
2=per1day
#endif //GLOBALVARS_H
/*------------fileIO.h----------------------------------------------------------*/
#ifndef FILEIO_H
#define FILEIO_H
void writeToFile(const void *buffer,const int &unitSize,const char
*filename="../globalsFile.txt");
int readFromFile(void *buffer,const long bufSize,const char
*filename="../globalsFile.txt");
#endif //FILEIO_H
/*------------fileIO.cpp----------------------------------------------------------*/
#include "fileIO.h"
#include <stdio.h>
void writeToFile(const void *buffer,const int &unitSize,const char
*filename)
{
FILE * pFile;
pFile = fopen (filename,"wt");
fwrite(buffer,unitSize,1,pFile);
fclose(pFile);
}
int readFromFile(void *buffer,const long bufSize,const char *filename)
{
FILE * pFile;
pFile = fopen (filename,"rt");
if (pFile==NULL) return (0);
fread (buffer,bufSize,1,pFile);
fclose (pFile);
return (1);
}
/*------------main.cpp----------------------------------------------------------*/
#include "fileIO.h"
#include "../globalVars.h"
#include <iostream.h>
struct myStruct{
int offset;
//unsigned char uChars[numOfGlobalVars-1];
unsigned char uChar1;
unsigned char uChar2;
unsigned char uChar3;
unsigned char uChar4;
} saveVars, getVars;
int main()
{
//init the global variables
appDateTimeOffset=99;
operationalState=96;
logSamplingPeriod=101;
logType=75;
changeLog=69;
//fill up the structure with the globalVariables values
saveVars.offset=appDateTimeOffset;
saveVars.uChar1=operationalState;
saveVars.uChar2=logSamplingPeriod;
saveVars.uChar3=logType;
saveVars.uChar4=changeLog;
writeToFile(&saveVars,sizeof(saveVars));
//reinit the globalVars
appDateTimeOffset=0;
operationalState=0;
logSamplingPeriod=0;
logType=0;
changeLog=0;
if (readFromFile(&getVars,sizeof(getVars)))
cout<<"all OK"<<endl;
//refill the globalVars with the readFromFile values
appDateTimeOffset=getVars.offset;
operationalState=getVars.uChar1;
logSamplingPeriod=getVars.uChar2;
logType=getVars.uChar3;
changeLog=getVars.uChar4;
cout<<appDateTimeOffset<<endl;
cout<<operationalState<<endl;
cout<<logSamplingPeriod<<endl;
cout<<logType<<endl;
cout<<changeLog<<endl;
}//main
/*-----------------------------END-------------------------------------------------------------*/
i have switched to 4 independent entries (the uChar# declarations) in
order to make it work... but thats pretty much it.. if you want to
compile it just change the uChar# to uChars[#]..
Thank you for your help.
nass
Hello everyone,
i am attempting to make a structure
#include "globalVars.h"
struct myStruct{
int offset;
unsigned char uChars[numOfGlobalVars -1];
} saveVars, getVars;
and i have #define numOfGlobalVars in globalVars.h... it does not
compile saying
main.cpp:23: error: 'struct myStruct' has no member named 'uChars',
when i try to access these uChars later on in my code.
should i not be able to do that?
nass
It worked for me. Tell us a little more about the compiler you've used
the version and stuff.
gangs.