请师父们帮忙看看
#include "Stdio.h"#include "Conio.h"
#include "string.h"
typedef struct node /*定义一个结构体*/
{
char name[50];
struct node* next;
}Name;
Name *n_node(Name *head) /*创建单链表*/
{
Name *p,*s;
int x,n;/* x为一个结点*/
if((head = (Name *)malloc(sizeof(Name))) == NULL) /*为头指针申请一个空间*/
{
printf("No set up accomplish\n");
}
head->name[0] = '\0';
head->next = NULL;
p = head;
/*在创建一个新节点 s */
if((s = (Name *)malloc(sizeof(Name))) == NULL)
{
printf("No set up accomplish!");
}
p->next = s;
s->next = p->next;
p = s;
printf("Please input your want set up node:");
scanf("%d",&x);
for(n=0;n<x;n++)
{
printf("Please input your name[ 50string nei]: ");
scanf("%s",s->name);
}
return head;
}
Name *find_node(Name *head,char *sname) /*查找一个名字*/
{
Name *p;
char *name;
p = head;
while( p != NULL )
{
name = p->name;
if(strcmp(name,sname) == 0)
{
printf("Find le");
return p;
}
else
p = p->next;
}
if(p == NULL)
{
printf("No find ");
return NULL;
}
}
int main()
{
Name *head;
char ch[50];
n_node(head);
printf("Please input your want find NAME:");
scanf("%s",ch);
find_node(head,ch);
getch();
return 0;
}
我输出一个字符串 进行查找 输出正确和错误 结果都 是No find
试了好长时间 得不到结果 所有请大家帮忙看看
多多指点 谢谢 先辈们;