0
I made a code with struct Pessoa
to save more than one note and print using pointer. My question: how do I print in function listar()
the two notes I recorded in the function main()
? I’m doing it right?
I put the two notes in the first index [0] to be able to test the function only.
I want to list the notes of the registered person.
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
struct pessoa{
int notas[4];
};
void listar(struct pessoa *n1){
int cont=0;
for(cont=0;cont<2;cont++){
printf("\n--Nota:");
//Duvida aqui:
printf("%d",(*(n1 + cont)->notas));
}
}
main(){
printf("\n Digite a nota:");
struct pessoa n1[10];
int i;
for(i=0;i<2;i++){
printf("\nDigite a nota:");
scanf("%d",&n1[0].notas[i]);
}
listar(n1);
}
If notes are an array of 4 positions you need to print element by element of the array and not the way you did.
– anonimo
And you want to list what? people and their notes or just the notes people registered?
– Maniero
I do this with the " * "? I don’t know for sure, I tried to put *(n1)->notes[cont], but I don’t know
– VitorLP
I want to list the notes of the registered person
– VitorLP