My program needs these functionalities:
NOTE: I did not include the codes for the numbers 1,2 & 4 since I already finished them. The 3rd one is my problem.
- The program should continuously allow input from the user as long the user still wants to. (Dynamically)
- Get the final grade of a student (average of frst_grade, scnd_grade, fnl_grade)
- Get the number of students per college.
- Get student name by inputting s_id.
My problem is how to compare the search input to the user input in s_college to get the number of students. The only way I know is by using strcmp() but it gives me this error: invalid conversion from 'char' to 'const char*' [-fpermissive]
So how do I compare these two to get the number of students per college?
#include<stdio.h>
#include<string.h>
#include<conio.h>
int i,n,sum,search,num=0,ctr=0;
char answer,choice,choice2,search2;
struct record{
int s_id;
char s_name[100];
char s_course;
char s_college[5];
int s_scoress;
}id[100],name[100],course,college[100],scores;
struct s_scores{
int frst_grade;
int scnd_grade;
int fnl_grade;
}first,second,final;
void ADD();
void COLLEGE();
void ID();
void COLLEGE(){
printf("Enter college (abbreviation only)");
scanf("%s",&search2);
for(i=0;i<num;i++){
if(strcmp(college[i].s_college,search2)==0);
ctr++;
}
printf("The number of students in %s is %d",search2,ctr);
search2
is achar
not a string. Correct it. – Hollingtonchar search2; ... strcmp(...,search2)
" is expected to make the compiler yell out a warning at you. Take warnings serious. – Baumgardnerstruct record{ int s_id; char s_name[100]; char s_course; char s_college[5]; int s_scoress; }id[100],name[100],course,college[100],scores;
is saying there are 100 instances of thestruct record
in an array namedid
and 100 instances of thestruct record
in an array namedname
and one instance of thestruct record
namedcourse
and 100 instances of thestruct record
in an array namedcollege
and one instance of thestruct record
namedscores
. This is (most likely) not what you want. – Notepaperstruct s_scores{ int frst_grade; int scnd_grade; int fnl_grade; }first,second,final;
is saying there are three instances of thestruct scores
with the names:frst_grade
scnd_grade
andfnl_grade
. This is (most likely) not what you want. – Notepaperscanf("%s",&search2);
the variablesearch2
is declared as a single char!!! Given the rest of the code snippet, the variablesearch2
needs to be declared as:char search[5];
The rest of the code is not posted, but I suspect this kind of error can be found else where in the code. Then whensearch2
is properly declared, the call to scanf() should be:if (1 != scanf( "%4s", search2 ) ) { // handle error }
. – Notepaperenum
statement or#define
statements to give those magic numbers meaningful names, then use those meaningful names throughout the code. – Notepaper;
, so it does nothing. If the code were properly indented (including any optional braces) then the problem of 'no body' in the 'if' code block would have been obvious. – Notepaper