69,371
社区成员
发帖
与我相关
我的任务
分享
[User:liangdong Time:22:58:15 Path:~/c]$ cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
char buf[100];
FILE *fp = fopen("data.txt", "r");
if (!fp) {
return -1;
}
while (fgets(buf, 100, fp) != NULL) {
int len = strlen(buf);
if (buf[len - 1] == '\n') {
buf[len - 1] = '\0';
}
char *sep = strchr(buf, ',');
if (sep != NULL) {
*sep = '\0';
}
printf("%s\n", buf);
}
return 0;
}
[User:liangdong Time:22:58:07 Path:~/c]$ ./main
123.456
235.89
947
[User:liangdong Time:22:58:11 Path:~/c]$ cat data.txt
123.456,
235.89,
947,345
[User:liangdong Time:22:58:15 Path:~/c]$