Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <Windows.h>
- struct studentInfo {
- struct {
- char *name;
- char *surname;
- char *patronymic;
- };
- union {
- int height;
- int weight;
- };
- };
- char* stringInput(char *text) {
- int i = 0, key = 0;
- printf("%s", text);
- char *string = nullptr;
- if (!(string = (char*)malloc(sizeof(char)))) {
- return NULL;
- }
- while ((key = getchar()) != '\n') {
- string = (char*)realloc(string, sizeof(char) * (i + 1));
- string[i++] = key;
- }
- string[i] = '\0';
- return string;
- }
- int numberInput(int verification, char* string) {
- int number = 0;
- char buffer = 0;
- printf("%s", string);
- printf(" ");
- while ((!(scanf_s(" %d%c", &number, &buffer, 1))) || (buffer != '\n') || (number < verification) || (number <= 0)) {
- rewind(stdin);
- printf(" You've entered the wrong value. Please, enter again: ");
- }
- return number;
- }
- void studentsInfoOutput(struct studentInfo* studentInitial, int checkup, int studentsAmount) {
- for (int i = 0; i < studentsAmount; i++) {
- if (checkup == 1) {
- printf("___________________\n");
- printf(" Surname: %s\n", studentInitial[i].surname);
- printf(" Name: %s\n", studentInitial[i].name);
- printf(" Patronymic: %s\n", studentInitial[i].patronymic);
- printf(" Height is: %d\n", studentInitial[i].height);
- printf("___________________\n");
- }
- if (checkup == 2) {
- printf("___________________\n");
- printf(" Surname: %s\n", studentInitial[i].surname);
- printf(" Name: %s\n", studentInitial[i].name);
- printf(" Patronymic: %s\n", studentInitial[i].patronymic);
- printf(" Weight is: %d\n", studentInitial[i].weight);
- printf("___________________\n");
- }
- }
- }
- struct studentInfo studentInfoInput() {
- int key = 0;
- struct studentInfo studentInitial;
- studentInitial.name = stringInput(" Enter student name: ");
- studentInitial.surname = stringInput(" Enter student surname: ");
- studentInitial.patronymic = stringInput(" Enter student patronymic: ");
- printf(" What you would like to enter: weight(W) or height(H)?\n Please, press the appropriate button(W/H): ");
- while (((key = getchar()) != 'H' && key != 'W')) {
- printf(" You've entered the wrong value. Please, enter again: ");
- rewind(stdin);
- }
- if (key == 'H') {
- studentInitial.height = numberInput(0, " Enter student height: ");
- }
- else if (key == 'W') {
- studentInitial.weight = numberInput(0, " Enter student weight: ");
- }
- return studentInitial;
- }
- int parityCheck(int &checkup, char* argv[]) {
- if (!(strcmp(argv[1], "Height")) || !(strcmp(argv[1], "height"))) {
- return 1;
- }
- if (!(strcmp(argv[1], "Weight")) || !(strcmp(argv[1], "weight"))) {
- return 2;
- }
- }
- int studentSearch(int studentInitial, int checkup) {
- if (studentInitial == checkup)
- return 1;
- else return 0;
- }
- int main(int argc, char *argv[]) {
- int i = 0;
- int checkup = 0;
- int studentsAmount = 0;
- int switchOption = 0;
- int hey = 0;
- struct studentInfo *studentInitial;
- if (!(studentInitial = (struct studentInfo*)malloc(sizeof(struct studentInfo)))) {
- printf(" Memory error.\n");
- return 0;
- }
- printf(" Hello!\n");
- do {
- while ((switchOption = numberInput(1, " 1. Enter students information. \n 2. Required information output. \n 3. Exit. \n")) > 3) {
- system("CLS");
- printf(" You've entered the wrong value. Please, enter again: ");
- rewind(stdin);
- }
- switch (switchOption) {
- case 1: {
- system("CLS");
- studentsAmount++;
- if (!(studentInitial = (struct studentInfo*)realloc(studentInitial, sizeof(struct studentInfo) * studentsAmount))) {
- printf(" Memory error.\n");
- return 0;
- }
- studentInitial[studentsAmount - 1] = studentInfoInput();
- break;
- }
- case 2: {
- system("CLS");
- checkup = parityCheck(checkup, argv);
- studentsInfoOutput(studentInitial, checkup, studentsAmount);
- break;
- }
- case 3: {
- system("CLS");
- printf("Thank you for using this programm! Have a good day!\n\n");
- break;
- }
- }
- } while (switchOption != 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement