const char *sentence = "He was not in the cab at the time.";
printf("\"%s\" has %d spaces\n", sentence, (int) ^ {
int i = 0;
int countSpaces = 0;
while (sentence[i] != '\0') {
if (sentence[i] == 0x20) {
countSpaces++;
}
i++;
}
return countSpaces;
});
このコードは単純に文字列内の空白をカウントしますが、何らかの理由で 8 ではなく 1606416608 と表示されます。何が問題なのか正確にはわかりません。助けてくれてありがとう!