- 论坛徽章:
- 0
|
1M并不算大,如果数据格式不变,可以采用这种比较不灵活的办法,效率应该能比脚本高点?没比较过
- #include <stdio.h>
- int main(int argc, char *argv[])
- {
- char buff[128];
- FILE *fp;
- if (argc != 2)
- {
- printf("USAGE: %s file.txt\n", argv[0]);
- return 1;
- }
- if ((fp = fopen(argv[1], "r")) == NULL)
- {
- printf("can't open %s\n", argv[1]);
- return 1;
- }
- while (fscanf(fp, "%s\n", buff) > 0)
- {
- printf("%c%c,%c%c%c%,%c%c%c,%c%c%c%c,%c%c\n", \
- buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6], \
- buff[7], buff[8], buff[9], buff[10], buff[11], buff[12], buff[13]);
- }
-
- fclose(fp);
- return 0;
- }
复制代码
- gcc a.c -o a.out
- a.out test.txt
复制代码 |
|