<div style="margin-top:5.76pt;margin-bottom:0pt;margin-left:.5in;text-indent:-.5in;text-align:left;"><font size="3">1.<span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;">mycat</span><span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;"></span><span style="font-family:'맑은 고딕';color:#000000;font-weight:bold;vertical-align:baseline;">명령 </span><span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;">(</span><span style="font-family:'맑은 고딕';color:#000000;font-weight:bold;vertical-align:baseline;">유닉스의 </span><span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;">cat </span><span style="font-family:'맑은 고딕';color:#000000;font-weight:bold;vertical-align:baseline;">명령 기능과 동일</span><span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;">)</span><span style="font-family:Arial;color:#000000;font-weight:bold;vertical-align:baseline;"> 구현</span></font></div> <div class="O1" style="margin-top:4.8pt;margin-bottom:0pt;margin-left:.81in;text-indent:-.31in;text-align:left;"><font size="3"><span style="font-family:Arial;">–</span><span style="font-family:Arial;color:#000000;vertical-align:baseline;">mycat</span><span style="font-family:Arial;color:#000000;vertical-align:baseline;"> [-n] [filename1 filename2 … ]</span></font></div> <div class="O1" style="margin-top:4.8pt;margin-bottom:0pt;margin-left:.81in;text-indent:-.31in;text-align:left;"><font size="3"><span style="font-family:Arial;">–</span><span style="font-family:'맑은 고딕';color:#000000;vertical-align:baseline;">옵션처리</span><span style="font-family:Arial;color:#000000;vertical-align:baseline;">: -n</span></font></div> <div class="O1" style="margin-top:4.8pt;margin-bottom:0pt;margin-left:.81in;text-indent:-.31in;text-align:left;"><font size="3"><span style="font-family:Arial;">–</span><span style="font-family:Arial;color:#000000;vertical-align:baseline;">20</span><span style="font-family:'맑은 고딕';color:#000000;vertical-align:baseline;">개까지 파일명 처리</span></font><span style="font-size:medium;text-indent:-.25in;font-family:Arial;">–</span><span style="font-size:medium;text-indent:-.25in;font-family:'맑은 고딕';vertical-align:baseline;">파일명이 주어지지 않을 경우 표준 입력 장치로 입력된 정보를 화면에 출력하도록 구현한다</span><span style="font-size:medium;text-indent:-.25in;font-family:Arial;vertical-align:baseline;">.</span></div> <div class="O1" style="margin-top:4.8pt;margin-bottom:0pt;margin-left:.81in;text-indent:-.31in;text-align:left;"><span style="font-size:medium;text-indent:-.25in;font-family:Arial;vertical-align:baseline;"><br></span></div><font size="2">가 문제인데 개별적으로는 돌아가는데 모두 한 코드에 넣으니 파일을 열지를 못하고 파일명이 없을 때로 인식되어 계속 값을 입력받네요...</font> <div><font size="2">옵션 -n을 하던 안하던 파일명이 입력이 안될경우에 입력된 정보를 명령어 echo처럼 출력하고 파일 이름이 입력되었을 때 파일을 열 수 있도록 코딩을 하려면 어떻게 수정해야 좋을지 좀 가르쳐주십시오<br></font><br></div> <div>아래는 코드입니다.</div> <div><br></div> <div> <div>#include <stdio.h></div> <div>#include <string.h></div> <div><br></div> <div>int checkOption(int ac, char *av[]);</div> <div><br></div> <div><br></div> <div>int main(int ac, char *av[])</div> <div>{</div> <div><span style="white-space:pre;"> </span>FILE *fp;<span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>int ch;</div> <div><span style="white-space:pre;"> </span>int nl;</div> <div><span style="white-space:pre;"> </span>int line = 1;</div> <div><span style="white-space:pre;"> </span>int num = 1;</div> <div><span style="white-space:pre;"> </span>char s[11];</div> <div><span style="white-space:pre;"> </span>int i=0;</div> <div><span style="white-space:pre;"> </span>if((fp = fopen(av[0], "")) == NULL){</div> <div><span style="white-space:pre;"> </span>printf("type any text : ");</div> <div><span style="white-space:pre;"> </span>fgets(s,sizeof(s),stdin);</div> <div><span style="white-space:pre;"> </span>puts(s);</div> <div><span style="white-space:pre;"> </span>return 0;<span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>}</div> <div><br></div> <div><span style="white-space:pre;"> </span>for(int i = 1; i < ac; i++){</div> <div><br></div> <div><span style="white-space:pre;"> </span>if (num>20)</div> <div><span style="white-space:pre;"> </span>break;</div> <div><span style="white-space:pre;"> </span>if (strcmp(av[i], "-n") == 0){</div> <div><span style="white-space:pre;"> </span>printf("%d ", line++);</div> <div><span style="white-space:pre;"> </span>i++;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>if((fp = fopen(av[i], "r")) == NULL){</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>printf("Can't open %s\n", av[i]);</div> <div><span style="white-space:pre;"> </span>return -2;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>else{</div> <div><span style="white-space:pre;"> </span>num++;<span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>while((ch = fgetc(fp)) != EOF){</div> <div><span style="white-space:pre;"> </span>fputc(ch, stdout);</div> <div><span style="white-space:pre;"> </span>if (strcmp(av[1], "-n") == 0){<span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>if (ch == '\n'){</div> <div><span style="white-space:pre;"> </span>printf("%d ", line++);</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>fclose(fp);</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>}<span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>if (strcmp(av[1], "-n") == 0)</div> <div><span style="white-space:pre;"> </span>printf("\r");</div> <div><span style="white-space:pre;"> </span>return 0;</div> <div>}</div></div> <div><br></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.