#include <stdio.h>
#include <malloc.h>
#include <math.h>
int main()
{
int i, kor, eng, math;
int num;
int *sum;
double std_devi, average;
FILE *input_fp , *output_fp;
input_fp = fopen("c:\temp\file.inp", "r+");
output_fp = fopen("c:\temp\file.out", "w+");
if( input_fp == NULL )
{
fprintf(stderr, "can't open %s\n", "file.inp" );
return 0;
}
if( output_fp == NULL )
{
fprintf(stderr, "can't open %s\n", "file.out" );
return 0;
}
if( ( sum = (int *)malloc( sizeof(int)*3 )) == NULL )
{
fprintf(stderr, "memory allocation error %s\n", "sum" );
}
fscanf(input_fp, "%d \n",&num);
for(i=0;i<num;i++)
{
fscanf(input_fp,"%d %d %d",&kor,&eng,&math);
*sum=kor+eng+math;
average=(double)kor+eng+math/num;
std_devi=(double)(kor*kor+eng*eng+math*math)/num-average*average;
fprintf(output_fp,"%.1lf \n",average);
fprintf(output_fp,"%.1lf \n",sqrt(std_devi));
}
fclose( input_fp );
fclose( output_fp );
free( sum );
return 0;
}
이렇게 고쳐봤는데.... 계속해서 null로 빠진다 ㅜㅜ 어떻하지..
어디서 NULL로 빠지나요?
코드 실행하면 무조건 can't open file.inp만 뜬다는 말입니다.
http://mndd.tistory.com/m/post/54
http://cappleblog.co.kr/m/post/143
http://m.blog.naver.com/erbs1/10167608059