- 论坛徽章:
- 1
|
是下面这样吗?- #include "stdio.h"
- #include "stdlib.h"
- int main()
- {
- int i = 0;
- int j = 0;
- int snapshot=20;
- double a[51]={0};
- char file_name[256] = {0};
- FILE *fp = NULL;
- for (i = 1; i <= 1000; i++)
- {
- if (i % snapshot == 0)
- {
- j = i / snapshot;
- a[j] = a[j - 1] + 1;
- snprintf(file_name, sizeof(file_name), "position%03d.txt", j);
- fp = fopen(file_name,"w+");
- if (NULL != fp)
- {
- fprintf(fp, "%f\n", a[j]);
- fclose(fp);
- }
- else
- {
- printf("open file[%s] error.", file_name);
- }
- }
- }
- return 0;
- }
复制代码 又或是下面这样?- #include "stdio.h"
- #include "stdlib.h"
- int main()
- {
- int i = 0;
- int j = 0;
- int snapshot=20;
- double a[51]={0};
- FILE *fp = fopen("position.txt", "a+");
- if (NULL == fp)
- {
- printf("open file[%s] failed.\n", "position.txt");
- return -1;
- }
- for (i = 1; i <= 1000; i++)
- {
- if (i % snapshot == 0)
- {
- j = i / snapshot;
- a[j] = a[j - 1] + 1;
- fprintf(fp, "%f\n", a[j]);
- }
- }
- fclose(fp);
- return 0;
- }
复制代码 |
|