파일 입출력 코드 좀 봐주세요!

matat의 이미지

#include
#include
#define MAX_ROWS 12
#define MAX_COLS 5
int table[MAX_ROWS][MAX_COLS];
int stdID[MAX_ROWS];
char name[MAX_ROWS];
float avrg_std[MAX_ROWS];
void getID(FILE*infp,int stdID[]);
void getName(FILE*infp,char name[]);
void getScore (FILE*infp,int table[][MAX_COLS]);
void outData (FILE*outfp,int stdID[ ],char name[],int table[][MAX_COLS]);
void average_std (int table[][MAX_COLS],float avrg_std[]);

int main (void)

{
FILE*infp,*outfp;
int table [MAX_ROWS][MAX_COLS];
infp= fopen("c:\\test\\stdmark.txt","r");
outfp = fopen("c:\\test\\cal_average.txt","w");
getID(infp, stdID);
getName(infp,name);
getScore (infp,table);
average_std (table,avrg_std);
outData (outfp,stdID,name,table);


fclose(infp);
fclose(outfp);
return 0;
}
void getID(FILE*infp,int stdID[])
{

for(int row=0;row<12;row++)
fscanf(infp,"%d",stdID[row]);
}

void getName(FILE*infp,char name[])
{
for(int row=0;row<12;row++)
fscanf(infp,"%s",name[row]);
}

void getScore(FILE*infp,int table[MAX_ROWS][MAX_COLS])
{
for(int row=0;row<12;row++)
{for(int col=0; col<5; col++)
fscanf(infp,"*d*s%d%d%d%d%d",table[row][col]);
}
return;
}

void average_std (int table[][MAX_COLS],float avrg_std[])
{
for ( int row=0; row< MAX_ROWS; row++)
{
for(int col=0; col {
avrg_std[row] += table[row][col];
avrg_std[row] /= MAX_COLS;
}
}
return;
}

void average_sub (int table[][MAX_COLS],float avrg_std[])
{
for ( int row=0; row< MAX_ROWS; row++)
{
for(int col=0; col {
avrg_std[row] += table[row][col];
avrg_std[row] /= MAX_COLS;
}
}
return;
}
void outData (FILE*outfp,int stdID[],char name[],int table[][MAX_COLS])
{

for(int row=0;row<12;row++)
{
fprintf(outfp,"%d",stdID[row]);
fprintf(outfp,"%s",name[row]);
fprintf(outfp,"%.1f",avrg_std[row]);
for(int col=0; col<7; col++)
fprintf(outfp,"%d\n",table[row][col]);
}
return ;
}/**/

학번 이름 성적 5개형식 파일을 불러들여서
학번 이름 성적 5개 평균 파일을 내보내는 프로그램인데 어느 부분이 잘못 되었는지를 잘 모르겠네요..
어느 부분을 수정해야 할까요?

익명 사용자의 이미지

끝까지 안 작성되어있네요

raymundo의 이미지

딱히 이 질문글 올리신 분께 감정이 있는 건 아니고 생각난 김에 하는 말입니다만,
코드를 올렸더니 부등호 있는 곳부터 태그로 인식되어 잘려버리는 걸 모를 수는 충분히 있는데요.
글 올린 뒤에 코드가 깨지는데 이걸 어떻게 하죠 하며 리플로 묻지 않는다는 것은,
질문글 올린 다음에 자기 질문글이 제대로 남들에게 보이는지 확인을 한 번도 안 하고 창을 닫아버리는 걸까요?

암튼 소스 코드 올리실 때는

(code)
소스코드
(/code)

이렇게 code 태그로 둘러싸서 올리시면 (실제로는 괄호가 아니라 부등호를 쓰셔야 함)

소스코드

이렇게 보이면서 중간에 잘리는 일도 없고 들여쓰기도 잘 됩니다.

(code lang="c")
이런 식으로 언어 지정을 하면 신택스 하일라이트도 되고요.

좋은 하루 되세요!

HDNua의 이미지

문법 강조 기능이 있는 걸 처음 알았습니다. 감사합니다.

#include <stdio.h>
int main(int argc, const char *argv[]) {
 printf("Hello, world!\n");
 return 0;
}

저는 이렇게 생각했습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.