美文网首页
字符串翻转

字符串翻转

作者: 动感超人丶 | 来源:发表于2019-03-22 10:05 被阅读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;
        
    }
    
}

相关文章

网友评论

      本文标题:字符串翻转

      本文链接:https://www.haomeiwen.com/subject/gntlvqtx.html