Ex1

Exemplo de utilização de struct em C. Criação da estrutura pessoa.

#include<stdio.h>
 
typedef struct pessoa{
       char datanas[10];
       char nome[100];
       char endereco[200];
       int telefone;
} pessoa ;
 
int main(){
    pessoa p[3];
    int i;
    for(i=0;i<3;i++) {
 
      printf("entre com o nome\n");
      scanf("%s",&p[i].nome);
      printf("entre com a data de nascimento\n");
      getchar();
      gets(p[i].datanas);
      printf("entre com o endereco\n");
      gets(p[i].endereco);
      printf("entre com o telefone\n");
      scanf("%i",& p[i].telefone);
      getchar();               
   }
   for(i=0;i<3;i++) {
      printf("----------------------------------\n");               
      printf("Aluno %i \nNOME: %s\nENDERECO: %s\nDATA DE NASCIMENTO: %s\nTELEFONE: %i\n",i,p[i].nome,p[i].endereco,p[i].datanas,p[i].telefone);
   }
 
    system("pause");
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.