47,000 語を超えるファイル (辞書) の内容を取得しようとしています。私の目標は、乱数を生成し、ファイルの特定の行にある単語を見つけて、プログラムを実行するたびに異なる単語を取得し、その単語を出力することです。私は研究してきましたが、答えが見つかりませんでした。これは私がこれまでに持っているものです。文字しかかかりませんが、言葉が欲しい
//
// main.m
// wordaday
//
// Created by Eddy Guzman on 11/5/13.
// Copyright (c) 2013 Eddy Guzman. All rights reserved.
//
#import <Foundation/Foundation.h>
bool checkFile( NSString * path)
{
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: path ] == YES)
{
return TRUE;
NSLog (@"File exists");
}
else
{
NSLog (@"File not found");
return false;
}
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSString * path = @"/Users/eddy30/Eddy's Documents/School/Millersville/Fall2013/wordaday/dictionary.txt";
if(checkFile(path) == TRUE)
{
NSLog(@"WOHOOOO");
}
NSString* content = [NSString stringWithContentsOfFile:path];
//NSFileHandle *myFile = fileHandleForReadingAtPath:path;
int rand = arc4random_uniform(47049);
char Word = [content characterAtIndex:rand];
NSLog(@"Word of the day is: %c", Word);
}
return 0;
}