回答お願いします

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
光坂

回答お願いします

#1

投稿記事 by 光坂 » 14年前

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------------
といった感じに永遠に繰り返します

beatle
記事: 1281
登録日時: 14年前
住所: 埼玉
連絡を取る:

Re: 回答お願いします

#2

投稿記事 by beatle » 14年前

フォーラムルールはご覧になりましたか?
ソースコードはきちんとcodeタグで囲んで、
投稿する前にプレビューしてくださいね。

光坂

#3

投稿記事 by 光坂 » 14年前

すいませんでした。
もう一度熟読してから再度質問させていただきます。
ご注意ありがとうございました。

閉鎖

“C言語何でも質問掲示板” へ戻る