c언어 파일 입출력

C# 2014. 10. 7. 22:59

출처 : http://ra2kstar.tistory.com/53

#include <stdio.h>

int main(){

        FILE *fp ;

        int index;

        int data;


        fp = fopen("test.txt", "w");

        for(index = 0 ; index < 10 ; index++){

                fprintf(fp, "%d\n", index);

        }


        fclose(fp);


        fp = fopen("test.txt", "r");


        while(fscanf(fp, "%d", &data) != EOF){

                printf("%d\n", data);


        }


        fclose(fp);

        return 0;

}



결과

$ ~/a.out
0
1
2
3
4
5
6
7
8
9


'C#' 카테고리의 다른 글

Head First C# 77page  (0) 2014.04.28

자바 텍스트 한글자씩 읽기

JAVA/소스 2014. 10. 7. 19:58

import java.io.*;


public class Graph {


public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

try {

FileReader reader = new FileReader("sample1.inp");

int ch;

while((ch=reader.read())!=-1)

{

System.out.println((char)ch);

}

catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}



}


}



'JAVA > 소스' 카테고리의 다른 글

Java wav 재생  (0) 2015.01.10
자바 피보나치  (0) 2014.01.13
자바 팩토리얼  (0) 2014.01.13
자바 구조 예제  (0) 2014.01.13
Hello Java  (0) 2014.01.13