Advertisement
mdlib

RedeSocial

Apr 4th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<malloc.h>
  4. #include<string.h>
  5.  
  6. typedef struct redeSocial{
  7.     char N[15];
  8.     int T;
  9.     int A;
  10.     char *LA;
  11. }RS;
  12.  
  13. int main(){
  14.     RS *p;
  15.  
  16.     int qnt;
  17.    
  18.     printf("Digite quantos sao os usuarios: ");
  19.     scanf("%d", &qnt);
  20.  
  21.     p=(RS*)malloc(sizeof(RS)*qnt);
  22.  
  23.  
  24.     for(int i=0;i<qnt;i++)
  25.     {
  26.         setbuf(stdin, NULL);
  27.  
  28.         printf("Digite o nome do %d usuario: ", i+1);
  29.         fgets((p+i)->N, 15, stdin);
  30.         setbuf(stdin, NULL);
  31.  
  32.         (p+i)->T=strlen((p+i)->N);
  33.  
  34.         printf("Quantos amigos ele tem?\n");
  35.         scanf("%d", &((p+i)->A));
  36.         setbuf(stdin, NULL);
  37.  
  38.         (p+i)->LA=(char*)malloc(sizeof(char)*((p+i)->A));
  39.  
  40.         for(int j=0; j<((p+i)->A);j++){
  41.             printf("Qual o nome do %d amigo?\n", j+1);
  42.             fgets((p+i)->LA+j, 15, stdin);
  43.             setbuf(stdin, NULL);
  44.  
  45.         }
  46.     }  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement