SHARE
TWEET

Untitled

a guest Mar 26th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define MAX 100
  4.  
  5. struct student
  6. {
  7.     int n_o_p; //number of points
  8.     char name[20];
  9. };
  10.  
  11. int main()
  12. {
  13.     struct student arr_student[MAX];
  14.     char line[50];
  15.     memset(line,0,50);
  16.     int i=0;
  17.  
  18. while(fgets(line,50,stdin)!=NULL) //tento cyklus sluzi na to aby som dal veci do struktur
  19. {
  20. ///vyjadrenie cisla
  21.  
  22.       char *zaciatok=line;
  23.       char *koniec=NULL;
  24.  
  25.        while (*zaciatok == ' '){
  26.        zaciatok+=1;
  27.         }
  28.  
  29.        int x =strtol(zaciatok,&koniec,10);
  30.  
  31.        ///printf("hodnota x je %d\n",x);
  32.  
  33.        arr_student[i].n_o_p=x;
  34.  
  35.  
  36.  
  37.         ///vyjadrenie slova
  38.  
  39.  
  40.       char name[50];
  41.       memset(name,0,50);
  42.  
  43.       char *zaciatok_slova=koniec;
  44.  
  45.        while (*zaciatok_slova == ' '){
  46.        zaciatok_slova+=1;
  47.         }
  48.  
  49.       int velkost_mena = strlen(zaciatok_slova) - 1;
  50.  
  51.  
  52.  
  53.         memcpy(name,zaciatok_slova,velkost_mena);
  54.  
  55.  
  56.  
  57.  
  58.      //printf("meno je %s\n",name);
  59.  
  60.  
  61.         ///
  62.         strcpy(arr_student[i].name,name);
  63.       ///zadanie hodnot do pola struktur
  64.  
  65.  
  66.  
  67. i++;
  68.     }
  69.  
  70.  
  71.  
  72.  
  73. printf("Vysledky:\n");
  74.  
  75.  
  76.    for(int b=0; b < i; b++)
  77.     {
  78.         printf("%d %s\n",arr_student[b].n_o_p,arr_student[b].name);
  79.     }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. return 0;
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top