【发布时间】:2016-04-23 19:04:09
【问题描述】:
我有这行代码:
if (strcmp(n->data.name[i], searchName[i]) == 0)
我确定它不正确,我如何检查存储在链表中的名称的第一个字符?(错误是“n->data.name[i]” 谢谢
这是剩下的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct record
{
char name[20];
char surname[20];
char telephone[20];
}Record;
typedef struct node
{
Record data;
struct node *next;
}Node;
Node *head = NULL;
void search() {
Node *n = head;
Node *next = n;
int valid = 0;
int length2;
int valid2 = 0;
int valid3 = 0;
int count = 0;
char searchName[20];
printf(" Enter name, and/or surname, or tel no. : ");
gets();
gets(searchName);
length2 = strlen(searchName);
for (int i = 0; i < length2; i++)
{
valid2 = 0;
while (isspace(searchName[i]));
{
if (strcmp(n->data.name[i], searchName[i]) == 0)
{
valid2 = 1;
count++;
}
}
}
...
【问题讨论】:
-
试试
n->data.name[i] -
取决于您对链表的实现。显示结构声明。
-
如果
n->data.name是一个字符串,那么n->data.name[i]是一个单一的字符,你不要用string比较那些功能。 -
n->data.name)[i]- 这绝对是不是完整的错误消息,应该总是报告完全和完全在您的配置中显示。除了此处提供的单行代码外,我们对您的代码一无所知。我们只看到您向我们展示的内容;我们不介意读者。 -
我不会称之为停止。
标签: c struct linked-list nodes