/* 4-1 * Tanel Toova * Näites 2 on (vähemalt üks ;) viga, mis võib teatavatel * tingimustel programmile saatuslikuks saada. Leia ja paranda see! */ #include #include int main(int argc, char **argv) { int iCount; if(argc != 3){ fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } iCount = atoi(argv[2]); //the mistake is that if second cmd-line parameter is negative the for //loop becomes endless, in order to correct that, I change the fallowing //if statment from !iCount to iCount<1 if(iCount<1){ fprintf(stderr, "Don't know how to repeat \"Hello %s!\" %s times...\n", argv[1], argv[2]); return 2; } for(;iCount;iCount--){ printf("Hello %s!\n", argv[1]); } return 0; }