라이브러리 도와주세요.
낶아
질문 제목 : 정적라이브러리질문 요약 :주요기능을 정적라이브리로 생성해서
메인에서 사용하는건데.. 읽히지가 않습니다.질문 내용 :
mylib.c
#includestdio.h
#includestdlib.h
void input_score(float *score, int n)
{int c;
for(c=0;cn;c++)
scanf(%f,&score[c]);
}
void input_score_file(file* infile,float* score,int n)//파일을 읽어 score[c]에 저장
{ int c;
for(c=0; cn; c++)
fprintf(infile,%f,&score[c]);
}
void print_score(float* score,int n)//점수 출력
{int c;
for(c=0;cn;c++)
printf(점수:%f\n,score[c]);
}
float max_score(float* score,int n)//최대점수
{
float max;
if(n==1){
return score[0];
}
max=max_score(score,n-1);
if(maxscore[n-1])
{
return score[n-1];
}
return max;
}
float min_score(float* score,int n)//최소점수
{
float min;
if(n==1){
return score[0];
}
min=min_score(score,n-1);
if(minscore[n-1])
{
return score[n-1];
}
return min;
}
float sum_score(float* score,int n)//총합점수
{
float sum=0;
if(n0){
sum=score[n-1]+sum_score(score,n-1);
}
return sum;
}
void print_result(float max,float min,float sum,float mean)//결과값 출력
{
printf(최댓값 : %f \n최소값 : %f\n합친값 : %f\n평균값 : %f,max,min,sum,mean);
}
void save_result_file(file* outfile,float max,float min,float sum,float mean)//reusult.txt에 저장값
{
fprintf(outfile, 최고점수: %f, max);
fprintf(outfile, 최소점수: %f, min);
fprintf(outfile, 총합점수: %f, sum);
fprintf(outfile, 평균점수: %f, mean);
}
mylib.h
#include stdio.h
#include stdlib.h
void input_score(float* score,int n);
void input_score_file(file* infile,float* score,int n);
void print_score(float* score,int n);
float max_score(float* score,int n);
float min_score(float* score,int n);
float sum_score(float* score,int n);
void print_result(float max,float min,float sum,float mean);
void save_result_file(file* outfile,float max,float min,float sum,float mean);
main.c
#include stdio.h
#include stdlib.h
#include mylib.h
int main(void){
int n=0;
float* score;
float scoren;
float max=0,min=0,sum=0,mean=0;
file *infile,*outfile;
infile=(file*)fopen(score.txt,wt);//socre.txt 오픈
if(infile==null)
{
printf(에러: 입력 파일을 열 수 없읍!!\n\n);
return;
}
printf(학생수를 입력하세요:);
scanf(%d,&n);
score = (float *)malloc(n*sizeof(float));
if (score == null)
{
printf(에러: 동적 메모리 할당 실패!!!\n\n);
return;
}
input_score(score,n);
input_score_file(infile,score,n);//파일을 읽어 score[c]에 저장
print_score(score,n);//점수 출력
fclose(infile);//score.txt 닫음
max=max_score(score,n);//최고점수
min=min_score(score,n);//최저점수
sum=sum_score(score,n);//총합계
mean=sum/n;//평균
free(score);
print_result(max,min,sum,mean);//결과값 출력
outfile=(filile=(file*)fopen(result.txt,w);//result.txt 생성
if(outfile==null)
{
printf(에러: 입력 파일을 열 수 없읍!!\n\n);
return;
}
save_result_file(outfile, max, min, sum, mean);//result.txt에 저장될 값
fclose(outfile);//result.txt 닫음
}#include mylib.h에서 파일 소스를 읽을수 없다고 뜸니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |