fscanf
iOSプロジェクトのXcodeセットアップで次のコードを実行しており、2番目のコマンド、つまりfscanf(fid, "%d", &fIndex);
最初の反復自体でEXC_BAD_ACCESS(コード= 2、アドレス0x30)を取得していj = 0
ます
char word[wordLength]; // wordlength is set to 4
int numFiles = 0;
int fIndex = 0;
// create the word-fileIndex mapping
for(long i = 0; i < numWords; i++)
{
fscanf(fid, "%s%d", word, &numFiles);
vector<int> indexList(numFiles,0);
for(int j = 0; j < numFiles; j++)
{
fscanf(fid, "%d", &fIndex);
indexList[j] = fIndex;
}
wordIndexMap[word] = indexList;
}
fscanf
ただし、テストのために、次のように最初にスキャンする別の値を追加しました。
fscanf(fid, "%s%d%d", word, &numFiles, &fIndex);
そして、正常に実行され、ファイルから正しい値が読み取られました。
誰かがここで何が起こっているのか教えてもらえますか?
私の入力ファイルは次のようなものです:
abcd num_Index index1 index2 ....
例えば
1234 2 14 15
1235 3 5 2 6
1111 1 1