Wednesday, March 2, 2011

Character Arrays and Strings

Write a program to create a directory of students with roll numbers. The program should display the roll number for a specified name and vice-versa.

#include <stdio.h>
#include <stdio.h>
void main()
{
char student[50][20],roll_no[50][20],stu[50],roll[50];
int i,n,a;
clrscr();
printf("Enter number of students:");
scanf("%d",&n);
printf("Enter Roll no. and Students name But dont use sername\n");
for(i=1;i<=n;i++)
{
scanf("%s",roll_no[i]);
scanf("%s",student[i]);
}
clrscr();
printf("To know Roll no. of specified student press 1\n");
printf("To know Student name of specified Roll no. press 2:");
scanf("%d",&a);
if(a!=1||a!=2)
printf("Wrong input!");
if(a==1)
{
printf("Student Name:");
scanf("%s",stu);
for(i=1;i<=n;i++)
if(strcmp(student[i],stu)==0)
printf("Roll no.: %s",roll_no[i]);
}
if(a==2)
{
printf("Enter Roll No.:");
scanf("%s",roll);
for(i=1;i<=n;i++)
if(strcmp(roll_no[i],roll)==0)
printf("Student Name: %s",student[i]);
}
getch();
}

OUTPUT
Enter number os students : 10
Enter Roll no. and Students name But dont use sername
101  Suresh
102  Mahesh
103  Rajesh
104  Kamal
105  Sohan
106  Mohan
107  Rahul
108  Kamlesh
109  Surendra
110  Kavita

To know Roll no. of specified student press 1
To know Student name of specified Roll no. press 2 : 1
Student Name : Mahesh
Roll no. : 102

To know Roll no. of specified student press 1
To know Student name of specified Roll no. press 2 : 2
Roll no.: 102
Student Name :  Mahesh

To know Roll no. of specified student press 1
To know Student name of specified Roll no. press 2 : 3
Wrong Input!

1 comment:

  1. its showing error please correct it
    while running programme

    ReplyDelete