Our corporation office requires an application which will maintain all registered Universities in Chennai and that application should be user friendly in terms of searching a University. Create a structure called “University” with the following attributes: name, license number and area code.
Requirement: License number for a university should be 6 digits and the first 2 digits must be alphabets of Upper case letters and last 4 digits must be number.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct University
{
char name[100];
char license[10];
int area;
}u[10];
void main()
{
int i, n, r, k = 0, flag = 1, f2 = 1, j, search = 0;
char s[100];
printf("Enter the number of records\n");
scanf("%d", &n);
printf("Enter the details of %d universities\n", n);
for (i = 0; i<n; i++)
{
printf("Name of the University\n");
getchar();
scanf("%s", u[i].name);
j = strlen(u[i].name);
if (j <= 1)
{
f2 = 0;
break;
}
printf("License Number\n");
scanf("%s", u[i].license);
k = strlen(u[i].license);
if (k<1)
{
f2 = 0;
break;
}
if (k<6)
{
flag = 0;
}
else if ((u[i].license[0] >= 'A' && u[i].license[0] <= 'Z') && (u[i].license[1] >= 'A' && u[i].license[1] <= 'Z') && (u[i].license[2] >= '0' && u[i].license[2] <= '9') && (u[i].license[3] >= '0' && u[i].license[3] <= '9') && (u[i].license[4] >= '0' && u[i].license[4] <= '9') && (u[i].license[5] >= '0' && u[i].license[5] <= '9') && k == 6)
{
flag = 1;
}
else
{
flag = 0;
}
printf("Area Code\n");
scanf("%d", &u[i].area);
//printf("%d",u[i].area);
if (u[i].area <= 0)
{
f2 = 0;
}
}
if (flag == 0)
{
printf("Sorry! You have entered incorrect license number.");
}
else if (f2 == 0)
{
printf("Unable to continue");
}
else
{
printf("Enter the name of the University to be searched\n");
scanf("%s", s);
for (i = 0; i<n; i++)
{
if ((strcmp(u[i].name, s)) == 0)
{
search = 1;
}
}
if (search == 1)
{
printf("University is licensed one.");
}
else
{
printf("University is not found.");
}
}
}
when I give number of university as 3, then it did not take input for the 3rd university.
Test Case
Input 1
Enter the number of records
3
Enter the details of 3 universities
Name of the University
SRM
License Number
SR1234
Area Code
28
Name of the University
University of Madras
License Number
SP0904
Area Code
18
Name of the University
Bharath University
License Number
BU0101
Area Code
35
Enter the name of the University to be searched
SRM
Output 1
University is licensed one.