I am new in programming and I am developing a C application that gets data from a file. I open and analyze every line of this external file. Inside the loop I use a parser function that I previously created in order to get the desired data and parse it.
This is working good but now I need to save every parsed line (every message) in another array named buffer. Every message is limited to 200 chars and buffer to 1000 chars, so in buffer array could be stored exactly 5 messages. My external file have more than 5 messages so when the 6th message arrive, the 1st message should be remove from buffer. I am getting problems here because I do not know how to store values in buffer without overriding it.
This is the main function:
void main(void) {
FILE *fp = fopen ("file","r"); //open file
char line[200];
char parsed_line[200];
char *message;
char buffer [1000];
if (fp==NULL) printf ("the file open was not succeed");
else{
printf ("Device open!");
while(fscanf (fp, "%s", line) > 0 ){
if(strstr(line, "$GPRMC")){
message = parser(line, parsed_line); //gets a line and parse it
strcpy(buffer, message);
}
}
}
return;
}
I would be grateful if somebody could help me.