|
发表于 2020-7-13 15:19:34
|
显示全部楼层
我又试了一下,这么改
1、将winner的声明放到开头,声明改为char winner[4][10]
2、scanf改成这样
---------------------------------
最后修改过的程序应该是这样的- #include <stdio.h>
- #include <stdlib.h>
- #include<time.h>
- void randomchoose(char *p[],int b);
- int main() {
- int i,j;
- char winner[4][10];
- char *name[8]= {
- "Alice","Bob","Tom","Mike","Ann","John","White","Jerry"
- };
- int len=sizeof(name)/sizeof(name[0]);
- randomchoose(name,len);
- for( i=0; i<len; i++) {
- printf("%-8s",name[i]);
- if( (i+1)%2==0 ) {
- printf("\n");
- printf("the winner of this one match is:");
- int k=(i+1)/2;
- scanf("%s",winner[k-1]);
- }
- }
- printf("\n");
- return 0;
- }
- void randomchoose(char *p[],int b) {
- int j;
- int last=b-1;
- srand((unsigned)time(NULL));
- for(j=0; j<b-1; j++) {
- int random=rand()%b;
- char *temp=p[last];
- p[last]=p[random];
- p[random]=temp;
- last--;
- }
- }
复制代码 |
|