Objective-c学习三 控制台字符输入输出

#import<Foundation/Foundation.h>
/**NSLog后格式
%@     对象 
%d, %i 整数 
%u     无符整形 
%f     浮点/双字 
%x, %X 二进制整数 
%o     八进制整数 
%zu    size_t 
%p     指针 
%e     浮点/双字 (科学计算) 
%g     浮点/双字  
%s     C 字符串 
%.*s   Pascal字符串 
%c     字符 
%C     unichar 
%lld   64位长整数(long long) 
%llu   无符64位长整数 
%Lf    64位双字
argc是命令行总的参数个数
argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数
命令行后面跟的用户输入的参数

*/
int main(int argc,const char * argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  //http://blog.csdn.net/flashtao613/article/details/6285304 详细解释NSAutoreleasePool对象引用计数自动处理器
        //NSLog(@"中文");  //NSLog可以支持中文输出
    NSLog(@"argc=%d",argc);
    NSLog(@"主函数中第二个参数数组个数=%d",sizeof(argv));  //sizeof 字符指针数组的元素个数,元素个数代表了什么呢?argv[1,2,3]都不存在
    //NSLog(@"第一个数据是:%@",*argv[0]);
    NSLog(@"argv[%d] = %s\n", 0, argv[0]);  //输出格式带2个参数
    
    /*控制台输入整数并打印出整数*/
        int userInput;
    scanf("%i",&userInput);
    NSLog(@"you typed %i",userInput);

    /*控制台输入字符串并打印*/
    char str[50] = {0};
    printf("输入名字并回车:");
    scanf("%s",str);
    NSString *lastName = [NSString stringWithUTF8String:str];
    NSLog(@"lastName=%@",lastName);
        
    /*alloc对象必须显示释放**/
    NSString* string = [[NSString alloc] init];
        [string stringByAppendingString:@"Hello World!"];
    NSLog(@"string is:%@",string); //为何显示不出来正确字符串

        [pool drain];
    [string release];  //显示释放

    return (0);  //此处为main函数执行的最后一行,如果NSLog放在这一行下面,将不会执行
    
}