字符串逆序操作

来源:互联网 发布:怎么把淘宝下载到桌面 编辑:程序博客网 时间:2024/05/17 04:33

字符串逆序操作:

#include <stdio.h>#include <stdlib.h>#include <string.h>void swap(char *a, char *b){    char temp;    temp = *a;    *a = *b;    *b = temp;}int main(int argc, char *argv[]) {    volatile int i = 0;    char str[50];    memset(str, 0, sizeof(str));    printf("please input string now...\n");    scanf("%s", str);    //printf("%d %c\n", i, str[i]);     while(str[i] != '\0')    {           printf("i: %d   ", i);        printf("%d %c\n", i, str[i]);           i ++;    }    int len = strlen(str);    printf("len: %d\n", len);    for(i = 0; i < len/2; i++){        swap(&str[i], &str[len - i - 1]);       }    printf("change order string: %s\n", str);    return 0;}
原创粉丝点击