Skip to content
Snippets Groups Projects
Commit 20515a23 authored by Mohamed Yasar arafath K M's avatar Mohamed Yasar arafath K M :speech_balloon:
Browse files

initial commit

parent ce8cb76f
No related branches found
No related tags found
No related merge requests found
#include<stdio.h> #include<stdio.h>
#include<stdlib.h>
#include<string.h> #include<string.h>
struct data struct data
{ {
int register_no; int register_no;
char name[10]; char name[10];
char department[10]; char department[10];
float avg; float average;
}save[5]; }save[4]; //Struct variable declaration
int i; // declare a global variable
int Department_name(); // function declaration
int main() int main()
{ {
int i; int no_rec; //Storing a No.of record
FILE *fp = fopen("filetemplate.txt","r"); char ch; // character to print the file char by char
while (fscanf(fp,"%d %s %s %f",&save->register_no,save->name,save->department,&save->avg) != EOF) FILE *fp = fopen("filetemplate.txt","r+"); //Open the file with reading and write
while (fp!=NULL)
{
ch = fgetc(fp);
if (ch!=EOF)
{
printf("%c",ch);
}
else
break;
}
printf("%s","\n\n");
rewind(fp); // fseek(fp,SEEK_SET,0);
fscanf(fp,"%d",&no_rec);
for (i = 1; i <= 4; i++)
{ {
printf("%s\n",save->name); fscanf(fp,"%d %s %s %f",&save[i].register_no,save[i].name,save[i].department,&save[i].average);
} }
printf("%s",save->department); Department_name(save,no_rec);
fclose(fp);
return 0; return 0;
} }
int Department_name(struct data *save,int no_rec)
{
char inp[3];
int CSE_count=0,IT_count=0,avg=0,avg2=0;
for (i = 1; i <=no_rec; i++) //count and store the data in the count variable
{
if (!(strcmp(save[i].department,"CSE")))
{
CSE_count+=1;
}
else if (!(strcmp(save[i].department,"IT")))
{
IT_count+=1;
}
}
printf("CSE Department records : %d\n",CSE_count); //print the CSE department data separately
for (i = 1; i <= 4; i++)
{
if (!(strcmp(save[i].department,"CSE"))) // conditional check to find out CSE or Not
{
printf("%d\t%s\t%s\t%.2f\n",save[i].register_no,save[i].name,save[i].department,save[i].average);
}
}
printf("IT Department records : %d\n",IT_count); //print the IT department data separately
for ( i = 1; i <= 4; i++)
{
if (!(strcmp(save[i].department,"IT"))) // conditional check to find out CSE or Not
{
printf("%d\t%s\t%s\t%.2f\n",save[i].register_no,save[i].name,save[i].department,save[i].average);
}
}
printf("Enter the department name :");
scanf("%s",inp);
for (i = 1; i <= 4; i++)
{
if (!(strcmp(inp,save[i].department)))
{
if (avg<save[i].average)
{
avg=save[i].average;
avg2=i;
}
}
}
printf("High Avg Scored by\n");
printf("%d\t%s\t%s\t%.2f\n",save[avg2].register_no,save[avg2].name,save[avg2].department,save[avg2].average);
}
Noofrecords 4 4
1001 raj CSE 76.5 1001 raj CSE 76.5
1002 raja IT 80.2 1002 raja IT 80.2
1003 kumar CSE 90.2 1003 kumar CSE 90.2
1004 siva IT 65.8 1004 siva IT 65.8
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment