I am rather new to C and am probably doing something stupid but I can't find out why my string array isn't keeping the previous values while the grade is keeping all the values entered:
for(int i=0; i <noOfStudents; i++)
{
do{
printf("Please enter Student Full Name.");
//read string till enter
scanf(" %[^\n]", &studentFullName);
if(studentFullName == "")
{
printf("Invalid Student Name!\n\n");
getchar();
}
else
{
names[i] = studentFullName;
validStudentName = 1;
}
}while(validStudentName != 1);
do{
printf("Please enter Student Grade.");
scanf_s(" %d", &grade);
if(grade < -1 && grade >100)
{
printf("Invalid Student Grade!\n\n");
getchar();
}
else
{
grades[i] = grade;
validGrade = 1;
}
}while(validGrade != 1);
printf("\n");
}
studentFullName == ""does not work. You need to usestrcmpinstead, or in this case the more suitableif(!strlen(studentFullName)).studentFullNameand how you do it?