我有一个任务,我必须输入我想比较的名字的数量。然后我必须查看打印的名字是否在我打印的名称中重复。例如,如果我输入 5 Reagan, Bush, Reagan, Bush, Clinton,它会打印出“名字被重复”,但如果我输入 Davis 代表任何一个里根,它会拒绝。我尝试了 for 循环和 if 语句,但似乎找不到正确的输出。我正在使用 Dev C++,这就是我目前所拥有的。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
    char curname[30], firstname[30];
    int num, i, freq = 1;
    printf("How many names do you want to enter?\n");
    scanf("%d", &num);
    printf("What is the first name?");
    scanf("%s", firstname); 
    printf("Enter each of their names.\n");
    for (i=0; i<num; i++) {
        scanf("%s", curname);
        if (i==0) {
          strcmp(curname, firstname) != 0;
          printf("The first name in the list was repeated.\n"); 
        }
        else if (strcmp(curname, firstname) == 1)
          printf("The first name in the list was not repeated.\n"); 
    }
    system("pause");
    return 0;
}