+文字列の比較はstrcmpを使用
+未入力の場合はエラーとし、もう一度入力
scanf関数を使用して、数字を10回入力し、最も大きな奇数を表示
+未入力、半角数値以外の入力はエラーとし、もう一度入力
なのですが、エラー処理が出来ません。後々関数化しなければならないのですが
関数化もよく解りません;
自分で作った範囲は
#include<stdio.h> #include<string.h> #include<ctype.h> int main(){ int cnt=0, max1=0 , cnt2, su=0,moji=0; char str[50],max[50]; for(;cnt<10;cnt++){ printf("%d回目の入力をしなさい" , cnt+1); while(1){ str[moji] = getchar(); if(str[moji] == '\n'){ break; } moji++; } if(str[0] == '\n') printf("数値を入力してください。\n"); else break; } if(strcmp(str , max) == 1){ strcpy(max , str); } } printf("一番大きいのは%s\n" , max); printf("数字を10回入力してください。\n"); for(cnt2=0;cnt2<10;cnt2++){ printf("%d回目の入力をしてください。" , cnt2+1); scanf("%d" , &su); if((su%2) != 0){ if(su>max1){ max1 = su; } } } printf("一番大きい奇数は>%d" , max1); }ご助力お願いいたします。