Im trying to write a program that reads in strings and decides if the 1st one is repeated. I cant figure out how to store the first string into a variable, and compare that variable to the rest of the inputted strings.
ANY help or ideas would be freakin cool.
Code:
#include <strings.h>
#include <stdio.h>
int main () {
//Declared variables
int i;
int n;
char curname[250];
char lname[250];
int freq;
freq=1;
//Scans in n for n strings
printf("Enter n, followed by n Last names (each last name bust be a single word):\n");
scanf("%d",&n);
//Loops for n strings
for (i=1; i<=n; i++){
//Scans in strings
scanf("%s", curname);
//Stores first string in curname
if (i==1) {
strcpy(lname,curname); }
//checks for repeated names
if (strcmp(curname, lname) == 0) {
freq++;
}
}
if (freq > 1) {
printf("First name in list is repeated.\n"); }
else if (freq == 1) {
printf("First name in list is not repeated.\n");}
system("PAUSE");
return 0;
}