Feb 15, 2020

[C/Cpp] file I/O

#include <stdio.h>

int main(){

    FILE *fp;
    int i, j;

    fp = fopen("test.txt", "w");
    for(i=0; i<10; i++){
        fprintf(fp, "%d\n", i);
    }
    fclose(fp);


    fp = fopen("test.txt", "r");
    while(fscanf(fp, "%d", &j) != EOF){
        printf("%d\n", j);
    }
    fclose(fp);

    return 0; 
}

 

No comments:

Post a Comment