[plug] C help (only slightly Linux)

Leon Brooks leonb at ami.com.au
Mon Jul 20 18:39:29 WST 1998


Shackleton, Kevin wrote:
> I wrote this to read through the data file:

> #include <stdio.h>
> #include <string.h>

> int main() {
>   char string[80];
For 80-char records, add at least 2 for the \n at the end of the line,
and the \0 terminating the string.
>   char header[6];
At least [7] (remember the \0 at the end) -- heck, make it [20]!
>   do {
>     gets(string);
>     strncpy(header,string,6);
header[7] = '\0';	/* safety */
>     if(strcmp(header,"$GPRMC"))
>       printf(string);
>   } while (!eof());
>   return 0;
> }
> 
> However this doesn't work undet linux (core dump).  I assume that it's
> because there's no null termination on header.

Possibly. (-:


More information about the plug mailing list