Read in n, then n lastnames, and check to see if the first in the list is ever repeated again.
Here's what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int strcmp(char *w1, char *w2);
int main() {
int j, n;
char string1[30], string2[30];
printf("Enter n, followed by n last names (each last name must be a single word): ");
scanf("%d", &n);
for(j=0; j<n; j++)
{
scanf("%s", string1);
}
if(strcmp(string1, string2))
printf("First name in the list is repeated\n");
else
printf("First name in the list is not repeated\n");
system("pause");
return 0;
}
I see the problem is that it lies within n amount of string that I am not going through every string to compare to the first one.
How will do compare every string to the first one?
Current output:
3
alex
alex
alex
Not repeated
------------------
3
alex
ash
peter
Not repeated
correct input should be:
5 Reagan Bush Clinton Bush Obama
First name in list is not repeated.
------------------------------
4 Bush Clinton Bush Obama
First name in list is repeated.
Thanks