I have problem with a function. I have a structure with student information as name, id number, marks etc. I am able to read and print all needed, but the problem is when i want to count the input equal names. For example if I enter to count name Iva, and it is present 3 times, to count 3. It returns 0 for what i used till now. Here is the code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name [31];
char ID[11];//personal code
long FN;//student number
};
int BrS;
student MasStud[35]; //array for number of students
char bf[5];
void readStud(student *st){
int i;
printf("-------------------\n");
printf("Enter name of a student:\n"); gets_s(st->name);
printf("Enter ID");gets_s(st->ID);
printf("Enter FN:"); scanf_s("%ld",&st->FN);
gets_s(bf);
}
void CountStudName(student*st){
int count, j, n, i;
char name1[31];
int FreqArr[31];
strcpy(st->name,name1);
printf("Search name occurrence: "); gets(name1);
for (i=0; i<BrS; i++)
FreqArr[i]=-1;
count=1;
for (j=i+1;j<BrS;j++)
{
if (strcmp(st->name,name1)==0)j ++;
count++;
FreqArr[j]=count;
}
printf("The searched name is %d times present\n", count);
}
void main() {
int i;
printf("Enter number of students:"); scanf_s("%d",&BrS);
gets_s(bf);
printf("-------------------\n");
for (i=0; i<BrS;i++) readStud(&MasStud[i]);
printf("-------------------\n");
CountStudName(&MasStud[i]);
_getch();
}
Thank you in advance for you kind help.