Hello World...
I have file which contains:
2005-12-30|23:59:58|FIRST NAME|LAST NAME
2005-12-30|23:59:59|FIRST NAME|LAST NAME
2005-12-30|24:00:01|FIRST NAME|LAST NAME
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc,char *argv[]){ FILE* pFIn=0; FILE* pFOut=0; char pBufIn =0; char puid[11]=""; struct tm tTime; int offset=0; int pipecount=0; int filesize=0; unsigned short bits=0; const int msgid[3]={11,8,9}; //---- --------------------------------// pFIn=fopen("./resend.txt","r"); pFOut=fopen("./resend_2.txt","a"); if(pFIn == NULL){ printf("File not found"); return 1; } if(pFOut == NULL ){ printf("File not created"); return 1; } fseek(pFIn,SEEK_SET,SEEK_SET); while(fgetc(pFIn)!=EOF){ fseek(pFIn,offset,SEEK_SET); for(filesize=0;filesize<msgid[filesize];filesize++) { while(pipecount<msgid[filesize]){ pBufIn=(char)fgetc(pFIn); if(pBufIn == '|') pipecount=pipecount+1; } offset=0; do { pBufIn=(char)fgetc(pFIn); if(pBufIn=='|')pipecount=pipecount+1; else{ switch(msgid[filesize]) { case 8: if(bits<=sizeof(tTime.tm_year)) tTime.tm_year=pBufIn; break; case 11: puid[offset]=(char)pBufIn; //puid=strcat(puid,(char *)pBufIn); break; } offset=offset+1; } }while(pipecount < msgid[filesize]+1); //insert a null character.... if(filesize==msgid[filesize])puid[offset]='\0'; } fprintf(pFOut,"%s\n",puid); pipecount=0; do pBufIn=(char)fgetc(pFIn); while(pBufIn != '\n'); //approached the end of the line offset=ftell(pFIn); } fclose(pFOut); fclose(pFIn); return 0; }
Question: How read each byte/char and insert them into a integer.
I want to insert the time and date accordingly based on < struct tm> type object.
Eg: struct tm Timer;
tm.tm_year=2005;
tm.tm_month=12;
and so on.
I am currently using fgetc to get each byte.
How do I go on about do this?
Question No2.
How to append a byte by byte to a pointer object:
char A='A';
char B='B';
/* HOW DO I THIS?
char* object=NULL;
*object=(char &)A;*object++;
*object=(char &)B;*object++;
*/