我很喜欢的一段程序——fgets()与strtol()的结合使用
来源:互联网 发布:qq农场刷经验软件 编辑:程序博客网 时间:2024/06/05 23:58
/** start_id_from_0.c* In the asm_45.Arc, the vertex id is started from 1 and ended at 45083421(include the skipped vertices), but in GPS,*the vertex id shoule be started from 0. And the problem is I just modify the first column to let the vertex id start*from 0, but I don't modify the trailing vertex id either, so this is this program function---Reserve the first column*and the other vertex id minus 1.** Copyright@Wang Jiawei, Shenzhen BGI, China, 2012-11-26* The latest revision@Wang Jiawei, Shenzhen BGI, China, 2012-11-26*/#include <stdlib.h>#include <stdio.h>#include <string.h>#define MAX_LINE_LEN 1024int start_id_from_0(char* filename){ FILE *fin, *fout; long original_id; char restarted_filename[100]; char line[MAX_LINE_LEN]; strcpy(restarted_filename, filename); strcat(restarted_filename, ".restarted"); printf("The restarted_filename=%s\n", restarted_filename); fin = fopen(filename, "r"); if (fin == NULL) { printf("Can not open the file %s\n", filename); } fout = fopen(restarted_filename, "w+"); if (fout == NULL) { printf("Can not open the file %s\n", restarted_filename); } memset(line, 0, MAX_LINE_LEN); char *source_str, *stopped_str; long i = 0; long j = 0; printf("------------0--------------\n"); while(fgets(line, MAX_LINE_LEN, fin) != NULL) { source_str = line; stopped_str = line; i++; j = 0; char *temp; while(1) { temp = stopped_str; original_id = strtol(source_str, &stopped_str, 10); if (temp == stopped_str) break; if (j == 0) { if (j == 0) { } else { fprintf(fout, "%ld ", original_id - 1); } j++; source_str = stopped_str; } fprintf(fout, "\n"); memset(line, 0, MAX_LINE_LEN); } fclose(fin); fclose(fout); printf("the total line = %ld\n", i); return 0;}int main(){ start_id_from_0("new_data6.Arc.del_wgt"); return 0;}
- 我很喜欢的一段程序——fgets()与strtol()的结合使用
- fgets fputs 的结合使用 ;gets puts的结合使用
- strtol函数的使用
- strtol函数的使用
- 其实我很喜欢说话的
- 这的天气我很喜欢
- 我很喜欢您的思路
- 我很喜欢现在的生活
- 我很喜欢的一首词
- fgets函数的使用
- fgets的使用
- fgets函数的使用
- 使用fgetc实现fgets的功能 参数与返回值的含义,同fgets
- 一首我很喜欢的诗
- fgets与gets的区别
- fgets与scanf的区别
- fgets()与gets()的区别
- fgets与gets的区别
- Hdu 2757 Ocean Currents
- 引入数组
- 人物
- quantum网络术语
- 冒泡法排序
- 我很喜欢的一段程序——fgets()与strtol()的结合使用
- 深入研究Hibernate之二:单向一对多
- Python学习 代码
- 考研与就业
- 卸载LDAP
- CodeSmith自动保存输出结果
- 单引号内引入变量 shell 命令输出赋值给变量,以及用变量替换命令
- 在线编辑器 日历控件的使用
- Socket通讯机制