利用は初めてなんですが どうしでもエラー表示がうまくできません
Posted: 2008年2月10日(日) 16:36
問題は~~~scanf関数を利用して、文字列を10回入力し、最もおおきな文字列を表示する
*未入力の比較はstrcmpを使用し
*未入力の場合はエラーとし、もう一度入力するようにする事。
よろしくお願いします
ソース
#include <stdio.h>
#include <string.h>
#define MAXN 10
void main(void) {
char str[100];
int i;
char max[256];
for(i=0; i<MAXN; i++)
{
Loop:
printf("文字列入力:\n");
scanf("%s",&str);
if (strlen(str)==0)
{
printf("入力エラー");
goto Loop;
}
if (strcmp(max,str)<0 )
{
strcpy(max,str);
}
}
printf("%s\n",max);
}
*未入力の比較はstrcmpを使用し
*未入力の場合はエラーとし、もう一度入力するようにする事。
よろしくお願いします
ソース
#include <stdio.h>
#include <string.h>
#define MAXN 10
void main(void) {
char str[100];
int i;
char max[256];
for(i=0; i<MAXN; i++)
{
Loop:
printf("文字列入力:\n");
scanf("%s",&str);
if (strlen(str)==0)
{
printf("入力エラー");
goto Loop;
}
if (strcmp(max,str)<0 )
{
strcpy(max,str);
}
}
printf("%s\n",max);
}