回答お願いします
Posted: 2012年4月30日(月) 12:02
strlenとstrcmpを自分で関数を作り入力された文字数と出現回数を数えるプログラムを作ったのですが、
for(j=0;j<i;j++)
{
printf("%d------------\n",j);
count1[j]=fstrlen(tango,j);
count2[j]=fstrcmp(tango,i,j,count1);
}
部分で18文字以上の単語を入力すると無限ループしてしまいます。
解決方法と、原因を教えていただけませんか?
UNIXを使用しています。
問題はjだと思うのですが、どうしてもわかりません
#include <stdio.h>
#include <string.h>
#define MAX 16
int fstrlen(char moji1[][MAX], int atai1);
int fstrcmp(char moji2[][MAX], int atai2,int atai3,int lencount[]);
int main(void)
{
int i,j,k;
int count1[MAX];
int count2[MAX];
char tango[25][MAX];
i=0;
while(tango[i-1][0] != '*')
{
printf("%dネヨフワ、ホアムテアク・ホマ、キ、?ッ、タ、オ、、(」ア」オハクサ嵓ハニ・",i+1);
scanf("%s",tango);
i++;
}
for(j=0;j<i;j++)
{
printf("%d------------\n",j);
count1[j]=fstrlen(tango,j);
count2[j]=fstrcmp(tango,i,j,count1);
}
printf("?サ惞・ スミクスイn");
for(k=0;k<i-1;k++)
{
printf("%d %d \n",count1[k],count2[k]);
}
}
int fstrlen(char moji1[][MAX],int atai1)
{
int i;
i=0;
while(moji1[atai1]!='\0')
{
i++;
}
return i;
}
実行結果
0------------
1------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
といった感じに永遠に繰り返します
for(j=0;j<i;j++)
{
printf("%d------------\n",j);
count1[j]=fstrlen(tango,j);
count2[j]=fstrcmp(tango,i,j,count1);
}
部分で18文字以上の単語を入力すると無限ループしてしまいます。
解決方法と、原因を教えていただけませんか?
UNIXを使用しています。
問題はjだと思うのですが、どうしてもわかりません
#include <stdio.h>
#include <string.h>
#define MAX 16
int fstrlen(char moji1[][MAX], int atai1);
int fstrcmp(char moji2[][MAX], int atai2,int atai3,int lencount[]);
int main(void)
{
int i,j,k;
int count1[MAX];
int count2[MAX];
char tango[25][MAX];
i=0;
while(tango[i-1][0] != '*')
{
printf("%dネヨフワ、ホアムテアク・ホマ、キ、?ッ、タ、オ、、(」ア」オハクサ嵓ハニ・",i+1);
scanf("%s",tango);
i++;
}
for(j=0;j<i;j++)
{
printf("%d------------\n",j);
count1[j]=fstrlen(tango,j);
count2[j]=fstrcmp(tango,i,j,count1);
}
printf("?サ惞・ スミクスイn");
for(k=0;k<i-1;k++)
{
printf("%d %d \n",count1[k],count2[k]);
}
}
int fstrlen(char moji1[][MAX],int atai1)
{
int i;
i=0;
while(moji1[atai1]!='\0')
{
i++;
}
return i;
}
実行結果
0------------
1------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
8------------
9------------
10------------
11------------
12------------
13------------
14------------
15------------
16------------
17------------
18------------
2------------
3------------
4------------
5------------
6------------
7------------
といった感じに永遠に繰り返します