c program

2008-04-05 10:49 pm
write a function mirror that reserves the characters of a string. to reverse a string, one approach is to swap the first and last elements,and then swap the second and the second last elements and so on.the process should stop when the middle of teh string is reached,
smple output:
enter a string:computer
mirror image of computer: retupmoc

回答 (1)

2008-04-06 2:07 pm
✔ 最佳答案
/* mirror 2008-04-05
reverses given word
*/
char *mirror(char* word)
{
int len=strlen(word),i;
char c;
for(i=0;i

2008-04-06 06:09:36 補充:
for(i=0;i< len/2;i++)
{
c=word[i]; word[i]=word[len-i-1];word[len-i-1]=c;
}
return word;
}

2008-04-06 06:10:06 補充:
int main(int argc, char* argv[])
{
char word[200];
printf("enter a string:");
scanf("%s",word);
printf("mirror image of computer:%s&#92;n",mirror(word));
return 0;
}


收錄日期: 2021-04-13 15:23:46
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080405000051KK01636

檢視 Wayback Machine 備份