一个奇怪的问题:为什么我不能交换字母

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 hzchenyao 的 blog

#include "stdio.h"
#include "string.h"
#include "time.h"
#include "stdlib.h"

void swap(char*, char*);
void main()
{
 char *race="abcdefghijklmnopqrstuvwxyz";
 int i,j,k;
 char *ptr;
 ptr=race;

 srand(time(null));
    i=1+rand()%10 ;
 printf("%d\n",i);
 k=0;
 if(i<=5) k+=3;
 if(i>=6) k+=4;

 swap(&race[1],&race[k]);

 for(j=0;j<26;j++)
 {
 printf("%c",race[j]);
 }


}

void swap(char* ptr1,char* ptr2)
{
 char temp;
 temp=*ptr1;
 *ptr1=*ptr2;
 *ptr2=temp;
}

本文关键:一个奇怪的问题:为什么我不能交换字母
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top