C语言创建与读写txt文件

xiaoxiao2021-02-28  12

#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { FILE *fp = fopen("loss.txt", "w"); if (fp == NULL){ printf("Failed to open file"); return 0; } double i, y; for (i = 0, y = 0; i < 100; i += 0.5){ fprintf(fp, "%f\t", i); y = sin(i); fprintf(fp, "%f\n", y); } fclose(fp); //FILE *fpread = fopen("loss.txt", "r"); //if (fpread == NULL) //{ // printf("Failed to open file "); // return 0; //} int a[10] = { 0 }; //int *a = new int[10]; //for (int i = 0; i < 10; i++) //{ // fscanf(fpread, "%d", &a[i]); // printf("%d ", a[i]); //} //fclose(fpread); //system("pause"); }
转载请注明原文地址: https://www.6miu.com/read-2450080.html

最新回复(0)