- //
- // main.c
- // foyon
- //
- // Created by hongyi fan on 13-3-2.
- // Copyright (c) 2013年 hongyi fan. All rights reserved.
- //
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int reverse_string(char *str);
- int main(int argc, const char * argv[])
- {
- // insert code here...
- //printf("Hello, World!jjj\\n");
- char *str = NULL; //声明char类型指针
- str = (char *)malloc(10); //为指针分配内存,并把内存的首地址 指向指针地址
- strcpy(str,"abcdefg");
- //printf("%c \\n",*(str+3)); //*取值
- reverse_string(str);
- return 0;
- }
- int reverse_string(char *str)
- {
- //printf("succes");
- int n = strlen(str);
- //printf("%d",n);
- int i;
- for(i=n-1;i > -1; i--)
- {
- printf("reverse is %c \\n", *(str + i));
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/290420149392.html
来源: http://www.codesnippet.cn/detail/290420149392.html