How would i get the following code to print 'error' or 'true' only once after the whole array comparison in task 2 instead of printing after comparing each section of the array?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main() {
char name_array[10][15];
const char * name[15];
int i;
task1:
for(i=0;i<10;i++){
printf("\nEnter your name:\n");
scanf("%s", name_array[i]);
}
task2:
system("cls");
printf("Enter your name: ");
scanf("%s", name);
for(i=0;i<10;i++){
if (strcmp(name_array[i], name)!=0){
printf("error\n");
} else if (strcmp(name_array[i], name)==0){
printf("true\n");
}
}
}