0

私のアプリケーションでは、ユーザーがコンソールから何らかの入力を入力できるようにする必要があり、その文字列 (大文字を除く) をパス ファイルの一部にする必要があります。次のコードがありますが、すべてがスムーズに実行されているように見えますが、ファイルは実際には作成されていません。if ブロックからエラー メッセージが表示されません。

#define DEBUGGER 1
NSLog (@"Username:");
char userInput[70];
fgets (userInput, sizeof userInput, stdin);
int c;
while ((c = getchar()) != '\n' && c != EOF);
if (userInput [strlen(userInput) - 1] == '\n') //In case the input string has # characters plus \n
    userInput[strlen(userInput) - 1] = '\0'; //Plus '\0', the '\n' isn't added and the if condition is false
NSFileManager * fm = [NSFileManager defaultManager];
NSString * string = [NSString stringWithUTF8String: userInput];
NSString * stringUppercase = [string uppercaseString];
NSString * dirUsername = [NSString stringWithFormat:@"~/Desktop/ProjAlleleData/Accounts/%@", stringUppercase.stringByExpandingTildeInPath];stringByExpandingTildeInPath];
#ifdef DEBUGGER
NSLog(@"DEBUGGER MESSAGE: Username Directory Path: %@", dirUsername);
#endif
if ([fm createDirectoryAtPath: dirUsername withIntermediateDirectories: YES attributes: nil error: NULL] != YES) {
    NSLog(@"Save File Creation Error.");
    return 1;}
4

1 に答える 1