Advertisement
palmerstone

Structure

Oct 30th, 2011
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7.  
  8. struct student
  9. {
  10. char name[100];
  11. int roll;
  12. int marks;
  13. };
  14. struct student ar[500];
  15.  
  16. int main()
  17. {
  18. int t, i = 0, j, k, l, a, b, c, d, x, y, z, n;
  19. char str[1000], str2[1000], *ptr;
  20.  
  21. freopen("input.txt", "r", stdin);
  22. for (; ;)
  23. {
  24. gets(str);
  25. if (feof(stdin)) break;
  26. l = 0, ptr = strtok(str, " ");
  27. while(ptr != 0)
  28. {
  29. if (l == 0) strcpy(ar[i].name, ptr);
  30. if (l == 1) ar[i].roll = atoi(ptr);
  31. if (l == 2) ar[i].marks = atoi(ptr);
  32. l++;
  33. ptr = strtok(0, " ");
  34. }
  35. i++;
  36. }
  37.  
  38. for (l = 0; l < i; l++) printf("%10s %10d %10d\n", ar[l].name, ar[l].roll, ar[l].marks);
  39. return 0;
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement