0
votes

Pourquoi ne puis-je pas obtenir la valeur correcte du pointeur de structure?

Je voudrais utiliser le PTR [1] -> Lecture de lecture dans la fonction, mais il affiche toujours 0.

Quelle méthode pour résoudre ce problème? p>

Merci. P> Merci. P >

struct cache_read_block
{
    unsigned short ReadLength;    // How many words
};
typedef struct cache_read_block CACHE_READ_BLOCK;

void getValue(CACHE_READ_BLOCK (*ptr)[100])
{
    printf("index %d\n", ptr[0]->ReadLength);
    printf("index %d\n", ptr[1]->ReadLength);
}

int main(void) {

CACHE_READ_BLOCK arr[100] = {0};

 arr[0].ReadLength = 10;
 arr[1].ReadLength = 5;

 getValue(&arr);

 system("pause");
 return 0;
}


0 commentaires

3 Réponses :


4
votes

Dans cette fonction

void getValue( const vCACHE_READ_BLOCK *ptr )
{
    printf("index %d\n", ptr[0].ReadLength);
    printf("index %d\n", ptr[1].ReadLength);
}


0 commentaires

-1
votes

Essayez ceci:

void getValue(CACHE_READ_BLOCK (*ptr)[100])
{
    printf("index %d\n", (*ptr)[0].ReadLength);
    printf("index %d\n", (*ptr)[1].ReadLength);
}


0 commentaires

-1
votes
struct cache_read_block
{
    unsigned short ReadLength;    // How many words
};
typedef struct cache_read_block CACHE_READ_BLOCK;

void getValue(CACHE_READ_BLOCK *ptr)
{
    printf("index %d\n", ptr[0].ReadLength);
    printf("index %d\n", ptr[1].ReadLength);
}

int main(void) {

CACHE_READ_BLOCK arr[100] = {0};

 arr[0].ReadLength = 10;
 arr[1].ReadLength = 5;

 getValue(&arr);

 system("pause");
 return 0;
}

1 commentaires

Votre réponse devrait expliquer ce que vous avez changé et pourquoi - les réponses de codes ne sont découragées