Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- struct student
- {
- char name[100];
- int id;
- int grades;
- };
- student* get_mem(int size) {
- return(student*)malloc(size * sizeof(student));
- }
- void input(student studentArr[], int len) {
- register int i;
- bool exit_cycle_check;
- int ascii_symbol;
- for (i = 0; i < len; i++) {
- printf("Person %d:\n", i + 1);
- const int ucll = 65; // Upper Case low limit ("A" имеет номер ASCII, равный 65)
- const int uchl = 90; // Upper Case high limit ("Z" имеет номер ASCII, равный 90)
- const int lcll = 97; // Lower Case low limit ("a" имеет номер ASCII, равный 97)
- const int lchl = 122; // Lower Case high limit ("z" имеет номер ASCII, равный 122)
- while (true) {
- exit_cycle_check = true;
- printf("Enter name = ");
- scanf("%s",&studentArr[i].name);
- for (register int j = 0; j < 100; j++) {
- ascii_symbol = studentArr[i].name[j];
- if (((ascii_symbol <= uchl) && (ascii_symbol >= ucll)) || ((ascii_symbol <= lchl) && (ascii_symbol >= lcll)) || (ascii_symbol == 0))
- continue;
- else
- exit_cycle_check = false;
- break;
- }
- if (exit_cycle_check)
- break;
- else
- printf("Incorrect input. Only letters are suitable\n");
- }
- while (true) {
- printf("Enter grades = ");
- scanf("%d",&studentArr[i].grades);
- if (studentArr[i].grades >= 0 && studentArr[i].grades <= 10)
- break;
- else
- printf("Incorrect input. Grade must be in range from 0 to 10\n");
- }
- printf("Enter id = ");
- scanf("%d",&studentArr[i].id);
- printf("\n");
- }
- }
- int main() {
- student* studentArr = get_mem(5);
- input(studentArr, 5);
- printf("------------------------\n\n");
- for (int i = 0; i < 5; i++) {
- printf("Person %d:\n", i + 1);
- printf("Name = %s\n", &studentArr[i].name);
- printf("ID = %d\n", studentArr[i].id);
- printf("Grades = %d\n\n", studentArr[i].grades);
- }
- delete []studentArr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement