これはこのような初心者の質問であるため、事前に申し訳ありません。これが私がやろうとしていることのステップです:
- 2つのテキストファイルを読み取ります(適切な名前と通常の単語のUNIX単語リストファイル)
- テキストを文字列に分割します
- 分離された文字列をリストごとに配列に配置します
- 配列を比較し、一致する数を数えます
何らかの理由で、このコードは継続的にnull一致を返します。私は何をしているのでしょうか?助けてくれてありがとう。
int main (int argc, const char * argv[])
{
@autoreleasepool {
// Place discrete words into arrays for respective lists
NSArray *regularwords = [[NSString stringWithContentsOfFile:@"/usr/dict/words" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];
NSArray *propernames = [[NSString stringWithContentsOfFile:@"/usr/dict/propernames" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];
// The compare and count loop
NSInteger *counter;
for (int i = 0; i < [propernames count]; i++) {
NSString *stringFromRegularWords = [regularwords objectAtIndex:i];
NSString *properNamesString = [propernames objectAtIndex:i];
if ([properNamesString isEqualToString:stringFromRegularWords]) {
counter++;
}
}
// Print the number of matches
NSLog(@"There was a total of %@ matching words", counter);
}
return 0;
}