I am trying to set a specific string in a 2D character array equal to another string in a 2D character array, so that I can delete the string of my first array by inputting a NULL string in it. Is there a way to make if(deleteCourse[0] == courseName[i]) work in my code?
char courseName[18][25];
char deleteName[1][25];
char empty[1][25] = {NULL};
printf("Enter your course name: ");
scanf(" %[^\n]s", &courseName[9]); // assume I input a course at row 9
printf("Enter your course name to delete: "); // typing the same name as courseName[9]
scanf(" %[^\n]s", &deleteCourse[0]);
for(int i = 0; i < 18; i++)
{
if(deleteCourse[0] == courseName[i]) // scanning for the same string name
{
strncpy(courseName[i], empty[0], 25); // using NULL, empty[0], to empty the string, courseName[i]
}
}
Aucun commentaire:
Enregistrer un commentaire