字符串翻转

2019-03-22  本文已影响0人  动感超人丶

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    char chars[] = "hello, world";

    charReverse(chars);
    
    NSLog(@"%s", chars);
}

void charReverse(char* chars){
    
    char* begin = chars;
    char* end = chars + strlen(chars) - 1;
    
    while (begin<end) {
        
        char temp = *begin;
        *(begin++) = *end;
        *(end--) = temp;
        
    }
    
}
上一篇 下一篇

猜你喜欢

热点阅读