i have made the program like the following
int main()
{
IN the parse function "fill1.Total_hourmeter" get filled after parsing the data
{
char buf_send[200];
memset(buf_send,'\0', sizeof(buf_send));
strcpy(b_Total_hourmeter,fill1.Total_hourmeter);
b_Total_hourmeter[8]='\0';
sprintf(buf_send,"%.2s",b_Total_hourmeter);
WriteToDataFile(buf_send);
}
#define BufferFilePath "C:\\Documents and Settings\\Administrator\\Desktop\\20sept_new\\20sept\\New_Nipro1\\NiproBuf.txt"
int WriteToDataFile(char* str)
{
FILE* log;
char szDate[12];
char szTime[12];
char buf_buf[2500];
memset(buf_buf, 0, sizeof(buf_buf));
_strdate( szDate );
_strtime( szTime );
sprintf(buf_buf,%s::%s:Info:%s, szDate, szTime, str);
log = fopen(BufferFilePath,a+);
if (log == NULL)
return -1;
fprintf(log,%s\n, buf_buf);
fclose(log);
return 0;
}
My function call is like this:-
struct a
{
char Total_hourmeter[8];
}fill1;
int main()
{
socket create
connect()/call
send call
recv callparse_recv_data(buffer)
{
write_to_buffer()
return 0;
}
void write_to_buffer()
{
char b_Total_hourmeter[8];
char buf_send[200];
memset(buf_send,'\0', sizeof(buf_send));
strcpy(b_Total_hourmeter,fill1.Total_hourmeter);
b_Total_hourmeter[8]='\0';
WriteToDataFile(buf_send);
printf("");
}
Now the problem is after writing data to file successfully my code breaks at "printf("");" in "write_to_buffer()" function saying "Run-Time Check Failure #2 - Stack around the variable 'b_Total_hourmeter' was corrupted.";
if i did something like this
void write_to_buffer()
{
....
WriteToDataFile(buf_send);
cin.ignore();
}
It works fine but i have to close the console my self,the programs doesn't ends itself as it ends when "return 0;" is written in any program