したがって、基本的に GCC コンパイラでコードをコンパイルすると、エラーや警告は表示されませんが、最初のデータを入力すると、次のように表示されます。
Bus error: 10.
何が間違っているのかわかりません。void anagramGrouping
問題は(最後の関数)から来ていると思います。ロジックに従うのに役立つ残りのコードも含めました。
#include <stdio.h>
#include <string.h>
#define Row 2
#define col 20
int wordCount = 0;
int groupCount = 0;
char wordList[Row][col];
char group[Row][col];
// this is where prototypes go
void sortword(char word[col]);
void anagramGrouping(char word[col], char copy[col]);
void resetGroup();
int main() {
int i; // used in for loop to 'get' the strings
char word[col];
resetGroup();
for (i = 0; i < Row; i++) {
scanf("%s", word);
sortword(word);
wordCount++;
}
}
void resetGroup() {
int i;
for (i = 0; i < Row; i++)
strcpy(group[i], " ");
}
void sortword(char word[col]) {
int i = 0;
char temp;
char copy[col]; // used to store a copy of the original word
strcpy(copy, word);
while (word[i] != '\0') {
int j = i + 1;
while (word[j] != '\0') {
if (word[j] < word[i]) {
temp = word[i];
word[i] = word[j];
word[j] = temp;
}
j++;
}
i++;
}
anagramGrouping(word,copy);
}
void anagramGrouping(char word[col], char copy[col]) {
int n;
if (wordCount == 0) {
strcpy(group[0], copy);
}
for (n = 0; n <= groupCount; n++) {
if (strcmp(group[n], word) == 0) {
strcpy(group[n], copy);
} else {
groupCount++;
strcpy(group[groupCount], copy);
}
}
}