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; }
3 Réponses :
Dans cette fonction
void getValue( const vCACHE_READ_BLOCK *ptr ) { printf("index %d\n", ptr[0].ReadLength); printf("index %d\n", ptr[1].ReadLength); }
Essayez ceci:
void getValue(CACHE_READ_BLOCK (*ptr)[100]) { printf("index %d\n", (*ptr)[0].ReadLength); printf("index %d\n", (*ptr)[1].ReadLength); }
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; }
Votre réponse devrait expliquer ce que vous avez changé et pourquoi - les réponses de codes ne sont découragées