Skip to content

Instantly share code, notes, and snippets.

@TzuYangLin
Last active August 29, 2015 14:07
Show Gist options
  • Save TzuYangLin/c3aaea7a6d419145d8d9 to your computer and use it in GitHub Desktop.
Save TzuYangLin/c3aaea7a6d419145d8d9 to your computer and use it in GitHub Desktop.
Example: Get the Info from File
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
int main(int argc, const char * argv[])
{
FILE *fd;
char buf[96];
char ip_str[16], hostname[16], id[6];
int temp, humi;
if ((fd = fopen("/tmp/test", "r")))
{
printf("fd2=%d\n", fd);
while (fgets(buf, 96, fd))
{
buf[strlen(buf)-1] = '\0';
sscanf(buf, "%s %s %s %d %d", ip_str, hostname, id, &temp, &humi);
printf("%s,%s,%s,%d,%d\n", ip_str, hostname, id, temp, humi);
}
fclose(fd);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment