Interrupt Control+C

Hi everybody.
I made a C program, but I'm having some doubts about how to implement an ISR. What I liked to do was that inside the loop instead of always opening and closing the files, write files only when made ^ C.
Can you help me?
Many thanks.

[code]
while(1){
logfile = fopen(filename, "a+");
gpslogfile = fopen(filename2, "a+");


if ((rs232res=read(rs232fd,rs232buf,MAXBUFLEN)) != -1)
{
rs232buf[rs232res]='';
fprintf(gpslogfile, "%s
", rs232buf);
strncpy(temp, rs232buf, 6);
temp[6] = '';
if(strcmp(temp, "$GPRMC") == 0)
{
strtok(rs232buf, ",");
xtime = strtok(NULL, ",");
strtok(NULL, ",");
xlat = strtok(NULL, ",");
xns = strtok(NULL, ",");
xlong = strtok(NULL, ",");
xew = strtok(NULL, ",");
fprintf(logfile, "--> %s - %s%s, %s%s
", xtime, xlat, xns, xlong, xew);
printf("--> %s - %s%s, %s%s
", xtime, xlat, xns, xlong, xew);
strncpy(lastxtime, xtime, 10);
lastxtime[10] = '';
}
rs232buf[0] = '';
}


/* PACKET CREATED BY THE CLIENT AND BROADCASTED */
sprintf(buf, "ID %d - time %s", msgID, lastxtime);

// usleep(100000);

time++;
if (time >= WAITTIME)
{
sendto(sockfdTX, buf, strlen(buf)*sizeof(char), 0, (struct sockaddr *)&their_addr, sizeof their_addr);
fprintf(logfile, "TX: ID %d - time %s - dest %s
", msgID, lastxtime, inet_ntoa(their_addr.sin_addr));
printf("TX: ID %d - time %s - dest %s
", msgID, lastxtime, inet_ntoa(their_addr.sin_addr));
msgID++;
time = 0;
}


fclose(logfile);
fclose(gpslogfile);

}[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories