次のような関数があります。
int lexWhitespace(TokenizerOutput* input) {
printf("he");
if (!(14 > input->toStillParse[0] > 8) && !(input->toStillParse[0] == 32)) {
// checks if the first character in the toStillParse section of input is whitespace.
return -1;
} else {input->tokenizerOutput[0] = input->toStillParse[0];}
for (int i = 1; ; i++) {
if ((14 > input->toStillParse[0] > 8) || (input->toStillParse[0] == 32)) {
// checks if the first character in the toStillParse section of input is whitespace.
input->tokenizerOutput[i] = input->toStillParse[i];
} else {return 0;}
}
}
この構造体を受け取ります:
struct TokenizerOutput {
const char* toStillParse; // holds the text that still needs to be parsed.
char* tokenizerOutput; // holds the text that was just output by tokenizer function.
};
typedef struct TokenizerOutput TokenizerOutput;
次のようにメイン関数で呼び出そうとすると:
int main(void) {
printf("hello\n");
TokenizerOutput j = {" k", " "};
printf("%s\n", (&j)->toStillParse);
lexWhitespace(&j);
return 0;
}
セグメンテーション違反が発生します。「彼」を出力しないため、関数 lexWhitespace が何かを実行する前にセグメンテーション違反が発生しています。なぜこれが起こっているのか分かりません。どんな助けでも大歓迎です。gcc 9.3.0 を使用しています。