Hi guys i have a problem with my code :
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <conio.h>
struct blahblah {
char id[11];
char name[30];
float gpa;
}lol[100];
int main(){
int count = 0;
char name [50][100] ;
for(int i =0;i<=4;i++){
printf ("Student %d\n",i+1);
printf ("ID: ");
gets(lol[i].id);
printf("Name: ");
gets(lol[i].name);
printf ("GPA : ");
scanf("%f",&lol[i].gpa);
fflush(stdin);
if (lol[i].gpa >= 3){
strcpy(name[i],lol[i].name);
count++;
}
}
if(count>0){
printf ("GPA ABOVE 3 :\n");
for(int i =0;i<count;i++){
printf ("%s\n",name[i]);
}
}
else{
for (int i =0;i<=4;i++){
printf ("Student %d\n",i+1);
printf ("Name : %s\t",lol[i].name);
printf ("ID : %s\t",lol[i].id);
printf ("GPA :%.2f\n",lol[i].gpa);
}
}
getch();
}
this program works fine as long as there's less than 4 people with 3 or above gpas, but it prints really weird lines once theres 4 or more people, i think the problem lies in line 25...
strcpy(name[i],lol[i].name);
any ideas??