파일에서 읽어오는 프로그램..
원술
#include stdio.h
main()
{
static char str0[] = 1번;
static char str1[] = 2번;
static char str2[] = 3번;
static char str3[] = 4번;
static char str4[] = 5번;
int no0=2014012100, no1=2014012101, no2=2014012102, no3=2014012103, no4=2014012104;
int i,j,suk[5];
static float kor[5] = {84,79,94,69,82};
static float eng[5] = {97,83,79,88,71};
float avg[5];
FILE *fp;
fp = fopen(d:\\0\\test.txt, w);
printf(%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str0,no0,kor[0],eng[0]);
fprintf(fp,%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str0,no0,kor[0],eng[0]);
printf(%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str1,no1,kor[1],eng[1]);
fprintf(fp,%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str1,no1,kor[1],eng[1]);
printf(%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str2,no2,kor[2],eng[2]);
fprintf(fp,%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str2,no2,kor[2],eng[2]);
printf(%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str3,no3,kor[3],eng[3]);
fprintf(fp,%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str3,no3,kor[3],eng[3]);
printf(%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str4,no4,kor[4],eng[4]);
fprintf(fp,%s 학생의 학번 = %d 국어 점수 = %f 영어 점수 = %f \n, str4,no4,kor[4],eng[4]);
printf(\n);
// 평균 점수
for(i=0; i5; i++) {
avg[i] = (kor[i] + eng[i]) / 2.0;
}
for(i=0; i1; i++) {
printf(%s 학생의 평균 점수 = %f \n, str0,avg[0]);
fprintf(fp,%s 학생의 평균 점수 = %f \n, str0,avg[0]);
}
for(i=0; i1; i++) {
printf(%s 학생의 평균 점수 = %f \n, str1,avg[1]);
fprintf(fp,%s 학생의 평균 점수 = %f \n, str1,avg[1]);
}
for(i=0; i1; i++) {
printf(%s 학생의 평균 점수 = %f \n, str2,avg[2]);
fprintf(fp,%s 학생의 평균 점수 = %f \n, str2,avg[2]);
}
for(i=0; i1; i++) {
printf(%s 학생의 평균 점수 = %f \n, str3,avg[3]);
fprintf(fp,%s 학생의 평균 점수 = %f \n, str3,avg[3]);
}
for(i=0; i1; i++) {
printf(%s 학생의 평균 점수 = %f \n, str4,avg[4]);
fprintf(fp,%s 학생의 평균 점수 = %f \n, str4,avg[4]);
}
printf(\n);
// 석차 구하기
for(i=0; i5; i++) suk[i]=1;
for(i=0; i5; i++) {
for(j=0; j5; j++) {
if(avg[i] avg[j]) {
suk[i]++;
}}}for(i=0; i5; i++)
printf(%d번 학생의 석차 = %d등 \n,i+1,suk[i]);
fprintf(fp,%d번 학생의 석차 = %d등 \n,i+1,suk[i]);
fclose(fp);
}///////제가 파일 만드는 것 까지는 했는데... 여기서 읽어오는 프로그램 방법좀 알려주세요...
-
늘솜
어떤것을 원하시는지 잘 모르겠네요.
현재 님이 만드신 test.txt를 읽는 방법은
char buf[257] = {0);
fp2 = fopen(\d:\\\\0\\\\test.txt\