提前抱歉,这是一个初学者的问题。以下是我正在尝试做的步骤:
- 读取两个文本文件(用于专有名称和常规单词的 unix 单词列表文件)
- 将文本分成字符串
- 将分隔的字符串放入每个列表的数组中
- 比较数组并计算匹配数
无论出于何种原因,此代码都会不断返回空匹配项。我可能在做什么?非常感谢您的帮助。
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;
}