Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
class:os2014f:hw1 [2014/09/11 09:54]
mhshin created
class:os2014f:hw1 [2025/10/13 12:45] (current)
Line 1: Line 1:
 +다음 코드에서 scanf의 문제를 제외한 문제점을 파악하고 해결책을 제시하여라.
 +
 +힌트: 컴파일은 문제가 없고 실행도 되지만 사용자 입력에 따라서 문제가 생길 수 있다.
 +
 +채점: 문제점 5점, 해결책 5점
 +
 +제출방식:​ 홈페이지 참조
 +
 <​code>​ <​code>​
- char *word_list[10][20]; ​// 10 words, each word has 20 byte, 19 letters+#include <​stdio.h>​ 
 +#include <​stdlib.h>​ 
 +#include <​random>​ 
 + 
 +int main( void ) 
 +
 + char word_list[10][20]; ​
  
  int word_cnt;  int word_cnt;
  
  printf("​How many words do you want?:"​);​  printf("​How many words do you want?:"​);​
- scanf("​%d",​ word_cnt);+ scanf("​%d", ​&word_cnt);
  
  printf("​Please enter %d words\n",​ word_cnt);  printf("​Please enter %d words\n",​ word_cnt);
  
  for( int i=0; i<​word_cnt;​ i++) {  for( int i=0; i<​word_cnt;​ i++) {
- printf("​Enter %d th word:",​ i);+ printf("​Enter %d th word:",​ i+1);
  scanf("​%s",​ word_list[i]);​  scanf("​%s",​ word_list[i]);​
  }  }
  
 +        printf("##​ Word List ##​\n"​);​
 +        ​
 + for( int i=0; i<10; i++) {
 + printf("​The %d th word is %s\n", i+1, word_list[i]);​
 + }
 +
 +        system("​pause"​);​
 +        ​
 +        return 0;
 +}
 </​code>​ </​code>​
  
 
class/os2014f/hw1.1410404098.txt.gz · Last modified: 2025/10/13 13:00 (external edit) · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki