Advertisement
BladeMechanics

String Handling

Feb 2nd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<Windows.h>
  5. #define STUDENTTOTAL 1
  6.  
  7. typedef struct address
  8. {
  9.     char municipality[15];
  10.     char province[15];
  11.     char city[10];
  12. }ADDR;
  13.  
  14. typedef struct student
  15. {
  16.     char name[30];
  17.     ADDR STaddress;
  18.     int Age;
  19.     char Gender; //M or F only
  20.     char course[10];
  21.     int yrLevel;
  22. }STUDENT;
  23.  
  24.  
  25. void gotoxy(int X, int Y)
  26. {
  27.     COORD coord;
  28.     coord.X = X;
  29.     coord.Y = Y;
  30.     SetConsoleCursorPosition(
  31.         GetStdHandle(STD_OUTPUT_HANDLE),
  32.         coord
  33.         );
  34. }
  35.  
  36. void strup(char *input)
  37. {
  38.     int index=0;
  39.     for (index; input[index] != '\0'; index++)
  40.         input[index] = toupper(input[index]);
  41. }
  42.  
  43. STUDENT getinfo()
  44. {
  45.     STUDENT input;
  46.     printf("\n\tPlease enter student information");
  47.     fflush(stdin);
  48.     printf("\n\n\tName: "); gets(input.name); strup(input.name);
  49.     printf("\n\tAddress\n");
  50.     printf("\n\t\tMunicipality: "); gets(input.STaddress.municipality); strup(input.STaddress.municipality);
  51.     printf("\n\t\tProvince: "); gets(input.STaddress.province); strup(input.STaddress.province);
  52.     printf("\n\t\tCity: "); gets(input.STaddress.city); strup(input.STaddress.city); fflush(stdin);
  53.     printf("\n\t\tCourse: "); gets(input.course); strup(input.course);
  54.     printf("\n\t\tYearLevel: "); scanf_s("%d",&input.yrLevel); fflush(stdin);
  55.     printf("\n\t\tAge: "); scanf_s("%d", &input.Age); fflush(stdin);
  56.     printf("\n\t\tGender(M/F): "); scanf_s("%c", &input.Gender, 1); input.Gender = toupper(input.Gender);
  57.     getchar();
  58.     getchar();
  59.     return input;
  60. }
  61. void printAllStudent(STUDENT *S)
  62. //display student information NAME COURSE YRLEVEL
  63. {
  64.     int index;
  65.     printf("\tName\t\t\t\t\tCourse\\Year\n");
  66.     for (index = 81; index; index--)printf("-");
  67.     int x = 8, y = 3;
  68.     for (index = 0; index<STUDENTTOTAL; index++)
  69.         gotoxy(x, y);
  70.     _cputs(S[index].name); x += 35;
  71.     gotoxy(x, y);
  72.     printf_s("%s-%d", S[index].course, S[index].yrLevel);
  73.     y++;
  74. }
  75.  
  76. void printAll(STUDENT input)
  77. {
  78.     printf("\n\n\tName: "); puts(input.name);
  79.     printf("\n\t\tGender(M/F): "); printf("%c", input.Gender);
  80.     printf("\n\t\tAge: "); printf("%d", input.Age);
  81.     printf("\n\t\tCourse: "); puts(input.course);
  82.     printf("\t\tYearLevel: "); printf("%d", input.yrLevel);
  83.     printf("\n\tAddress\n");
  84.     printf("\n\t\tMunicipality: "); puts(input.STaddress.municipality);
  85.     printf("\t\tProvince: "); puts(input.STaddress.province);
  86.     printf("\t\tCity: "); puts(input.STaddress.city);
  87. }
  88.  
  89. void main()
  90. {
  91.     STUDENT input[2];
  92.     input[0] = getinfo();
  93.     system("cls");
  94.     fflush(stdin);
  95.     input[1] = getinfo();
  96.     puts("Press any key to continue");
  97.     _getch();
  98.     printAll(input[0]);
  99.     printAll(input[1]);
  100.     _getch();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement