0 Soalan: bagaimana menukar nilai somthing dalam array menggunakan penunjuk tanpa menggunakan kurungan persegi [ditutup]

soalan dicipta di Wed, May 8, 2019 12:00 AM

ia memberi saya kesilapan kerana tidak dapat menggunakan kod tersebut kerana penuding

:)

#include <stdio.h>
#define LENGTH 31
void get_boom_number(int* a)
{
    printf("Enter Boom number\n");
    while(scanf("%d", &*a)==0) {printf("Illegal input, try again:\n");
    getchar();
    }
}
void play(int *boom,int n,char *players[])
{
    int i=*boom-1,j,swap;
    while(n>0)
    {
        while((i/n)>0)i-=n;
        for(j=i%n;j<n-1;j++)/* sliding the name of the loser to the end of the array so we can remain the array by the same formation(sorted well)*/
        {
            swap=players[j];
            players[j]=players[j+1];
            players[j+1]=swap;
        }

        i+= *boom-1;
        n--;
    }
}
int main()
{
    char * players[LENGTH]={"Tyrion Lannister","Daenerys Targaryen","Jon Snow","Arya Stark","Theon Greyjoy", "Joffrey Baratheon","Khal Drogo","Ted Mosby","Marshall Eriksen","Robin Scherbatsky"/*10*/,"Barney Stinson", "Lily Aldrin", "Tracy McConnell", "Ted Mosby", "Leonard Hofstadter","Sheldon Cooper", "Penny", "Howard Wolowitz", "Raj Koothrappali", "Bernadette Rostenkowski-Wolowitz"/*20*/,"Amy Farrah Fowler", "Gregory House", "Lisa Cuddy", "James Wilson","Eric Foreman", "Allison Cameron", "Robert Chase" ,"Lawrence Kutner", "Chris Taub","Remy 13 Hadley"/*30*/, "Amber Volakis"};
    int boom_number, i;
    get_boom_number(&boom_number);
    play(&boom_number,LENGTH,&players);
    printf("The order after the game is: \n");
    for(i=0; i<LENGTH-1; i++)
    {
        printf("%s, ",players[i]);
    }
    printf("%s.",players[LENGTH-1]);
    return 0;
}


mudah ... semua yang saya mahu ubah adalah kurungan ... saya tidak dapat menggunakannya, saya telah diberitahu. jadi saya memerlukan cara untuk menggunakan program yang sama tanpa kurungan pada fungsi: bermain.

    
0
  1. (players+i) adalah lokasi dan *(players+i) adalah isinya.
    2019-05-08 16: 13: 52Z
  2. players[j] bukanlah int.
    2019-05-08 16: 14: 47Z
  3. scanf("%d", &*a) - a adalah penunjuk sudah ~ > scanf("%d", a)
    2019-05-08 16: 16: 56Z
  4. terima kasih saya telah menetapkannya
    2019-05-08 16: 17: 33Z
0 Jawapan                              0                         
sumber diletakkan di sini