Last active
August 29, 2015 14:07
-
-
Save TzuYangLin/c3aaea7a6d419145d8d9 to your computer and use it in GitHub Desktop.
Example: Get the Info from File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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