《程序设计导引及在线实践》学习
P41
int MyItoa(char s[])
将s中以字符串形式存放的非负整数,转换成相应整数返回。
#include<stdio.h>#include<string.h>char result[101];// step: positive--right move, negative--left move char* moveReplace(char* s, int step){int i;for(i=0; i<strlen(s); i++){if(*(s+i)+step > 'Z'){result[i] = 'A' + (*(s+i) + step - 'Z' - 1);}else if(*(s+i)+step < 'A'){result[i] = 'Z' + (*(s+i) - 'A' + step + 1);}else{result[i] = *(s+i) + step;}}result[i] = '\0';return result;}int main(){char s[10] = "ABCXYZ";printf("%s\n",moveReplace(s,-2));}?
?
?
?
?
?