| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 412 人关注过本帖
标题:链表问题,新人求助,小弟感激不尽
只看楼主 加入收藏
lzysunny0103
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-18
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
链表问题,新人求助,小弟感激不尽
帮忙看一哈不知道为什么在第二十六行崩掉。ps:不晓得为什么p1->name读不进值









#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "simpio.h"
#include "strlib.h"
#include "string.h"
#include "checkname.h"
#include "checknumber.h"

typedef struct NODE{
    string name[20];
    string number[20];
    int score;
    struct NODE *next;
};
int i;
struct NODE *inputinfo(void)
{
    int a = 0,b = 0,c,n = 0;
    struct NODE *head,*p1 = NULL,*p2 = NULL;
    p1 = p2 = (struct NODE *)malloc(sizeof(struct NODE));
    head = NULL;
    printf("Please input the name of the student!input \"a\" to finish inputting!\n");
    while(a == 0)
    {
        strcpy(p1->name[n],GetLine());
        a = checkname(p1->name[n]);
        if(a == 0)
            continue;
        if(a == 1)
            printf("Successful inputting!\n");
    }
    printf("Please input the number of the student!\n");
    while(b == 0)
    {
        strcpy(p1->number[n],GetLine());
        b = checknumber(p1->number[n]);
        if(b == 0)
            continue;
        if(b == 1)
            printf("Successful inputting!\n");
    }
    printf("Please input the score of the student!\n");
    p1->score = GetInteger();
    for(c = 0;c <= 3;c++)
    {
        if((p1->score > 100)||(p1->score < 1))
            continue;
        else
            printf("Successful inputting!\n");
    }
    p1 = p2 = (struct NODE *)malloc(sizeof(struct NODE));
    i = 0;
    while(p1->name[n] != "a")
    {
        i = i + 1;
        if(i == 1)
            head = p1;
        else
            p2->next = p1;
        p2 = p1;
        p1 = (struct NODE *)malloc(sizeof(struct NODE));
        n = n + 1;
        printf("Please input the name of the student!input \"a\" to finish inputting!\n");
        while(a == 0)
        {
            strcpy(p1->name[n],GetLine());
            a = checkname(p1->name[n]);
            if(a == 0)
                continue;
            if(a == 1)
                printf("Successful inputting!\n");
        }
        printf("Please input the number of the student!\n");
        while(b == 0)
        {
            strcpy(p1->number[n],GetLine());
            b = checknumber(p1->number[n]);
            if(b == 0)
                continue;
            if(b == 1)
                printf("Successful inputting!\n");
        }
        printf("Please input the score of the student!\n");
        p1->score = GetInteger();
        for(c = 0;c <= 3;c++)
        {
            if((p1->score > 100)||(p1->score < 1))
                continue;
            else
                printf("Successful inputting!\n");
        }
    }
    p2->next = NULL;
    return(head);
}











搜索更多相关主题的帖子: include number 
2011-12-18 21:56
lzysunny0103
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-18
收藏
得分:0 
弄成这样也不行


#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "simpio.h"
#include "strlib.h"
#include "string.h"
#include "checkname.h"
#include "checknumber.h"

typedef struct NODE{
    string name;
    string number;
    int score;
    struct NODE *next;
};
int i;
struct NODE *inputinfo(void)
{
    int a = 0,b = 0,c,n = 0;
    struct NODE *head,*p1 = NULL,*p2 = NULL;
    p1 = p2 = (struct NODE *)malloc(sizeof(struct NODE));
    head = NULL;
    printf("Please input the name of the student!input \"a\" to finish inputting!\n");
    while(a == 0)
    {
        strcpy(p1->name,GetLine());
        a = checkname(p1->name);
        if(a == 0)
            continue;
        if(a == 1)
            printf("Successful inputting!\n");
    }
    printf("Please input the number of the student!\n");
    while(b == 0)
    {
        strcpy(p1->number,GetLine());
        b = checknumber(p1->number);
        if(b == 0)
            continue;
        if(b == 1)
            printf("Successful inputting!\n");
    }
    printf("Please input the score of the student!\n");
    p1->score = GetInteger();
    for(c = 0;c <= 3;c++)
    {
        if((p1->score > 100)||(p1->score < 1))
            continue;
        else
            printf("Successful inputting!\n");
    }
    p1 = p2 = (struct NODE *)malloc(sizeof(struct NODE));
    i = 0;
    while(p1->name != "a")
    {
        i = i + 1;
        if(i == 1)
            head = p1;
        else
            p2->next = p1;
        p2 = p1;
        p1 = (struct NODE *)malloc(sizeof(struct NODE));
        printf("Please input the name of the student!input \"a\" to finish inputting!\n");
        while(a == 0)
        {
            strcpy(p1->name,GetLine());
            a = checkname(p1->name);
            if(a == 0)
                continue;
            if(a == 1)
                printf("Successful inputting!\n");
        }
        printf("Please input the number of the student!\n");
        while(b == 0)
        {
            strcpy(p1->number,GetLine());
            b = checknumber(p1->number);
            if(b == 0)
                continue;
            if(b == 1)
                printf("Successful inputting!\n");
        }
        printf("Please input the score of the student!\n");
        p1->score = GetInteger();
        for(c = 0;c <= 3;c++)
        {
            if((p1->score > 100)||(p1->score < 1))
                continue;
            else
                printf("Successful inputting!\n");
        }
    }
    p2->next = NULL;
    return(head);
}
2011-12-18 22:07
hnuhsg1226
Rank: 9Rank: 9Rank: 9
来 自:中国
等 级:蜘蛛侠
威 望:2
帖 子:314
专家分:1314
注 册:2011-3-27
收藏
得分:20 
string是什么数据类型,如果只是输入字符串用char型的字符数组,输入和输出时,只用写数组名即可,相当于指针

我的地盘
2011-12-19 10:44
lzysunny0103
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-18
收藏
得分:0 
恩,谢了ls,回去果断改了一哈,已经运行得起了,3q
2011-12-27 10:00
快速回复:链表问题,新人求助,小弟感激不尽
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023417 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved