C 如何检查InsertList()中输入的用户名是否与数组等待列表中已有的用户名不相等?

C 如何检查InsertList()中输入的用户名是否与数组等待列表中已有的用户名不相等?,c,arrays,C,Arrays,如果名称已经在数组列表中,我想让用户输入另一个名称。我该怎么做 #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX_SIZE 12 #define MAX_LENGTH 25 char waitList[MAX_SIZE][MAX_LENGTH]; char numberInParty[MAX_SIZE]; int count = 0; void insertList()

如果名称已经在数组列表中,我想让用户输入另一个名称。我该怎么做

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 12
#define MAX_LENGTH 25

char waitList[MAX_SIZE][MAX_LENGTH];
char numberInParty[MAX_SIZE];
int count = 0;

void insertList() {
  char name[MAX_LENGTH];
  int number, i;
  printf("Name? ");
  scanf("%s", name);
  printf("Number of people in party? ");
  scanf("%d", &number);

  strcpy(waitList[count], name); 
  numberInParty[count] = number;
  printf("Inserted\n\n");
  count++; 
#包括
#包括
#包括
#定义最大尺寸12
#定义最大长度25
字符等待列表[最大大小][最大长度];
char numberInParty[最大大小];
整数计数=0;
void insertList(){
字符名称[最大长度];
整数,i;
printf(“姓名?”);
scanf(“%s”,名称);
printf(“参加聚会的人数?”);
scanf(“%d”和编号);
strcpy(等待列表[计数],名称);
numberInParty[计数]=数字;
printf(“插入的\n\n”);
计数++;

您希望迭代数组,并检查其中的每个元素是否是用户刚刚输入的
名称

因此,您需要知道数组的大小。C中没有用于检查数组长度的函数。但是,如果数组声明在与要检查的范围相同的范围内,则可以执行以下操作

int len = sizeof(waitList)/sizeof(waitList[0]);
然后,将
用于
循环和
strcmp

for ( int i = 0; i < len ; i++ ) {
    if ( strcmp(waitList[i], name) == 0 ) {
        printf("Name already exists. Please enter another ");
        scanf("%s", name);
    }
}
for(int i=0;i

您可以阅读有关strcmp的更多信息,您希望迭代数组并检查其中的每个元素是否是用户刚刚输入的
名称

因此,您需要知道数组的大小。C中没有用于检查数组长度的函数。但是,如果数组声明在与要检查的范围相同的范围内,则可以执行以下操作

int len = sizeof(waitList)/sizeof(waitList[0]);
然后,将
用于
循环和
strcmp

for ( int i = 0; i < len ; i++ ) {
    if ( strcmp(waitList[i], name) == 0 ) {
        printf("Name already exists. Please enter another ");
        scanf("%s", name);
    }
}
for(int i=0;i
你可以阅读更多关于strcmp的使用strcmp函数的信息,我想这是strcmp函数的重复