| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 496 人关注过本帖
标题:C,function不能用
取消只看楼主 加入收藏
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
结帖率:50%
收藏
 问题点数:0 回复次数:2 
C,function不能用
小弟刚学C 请多多指教
这是我的作业
不知道为什么我的第三个function不可以用。。。就是要印出我输入过的资料不能出来

程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
    char *student_name;
    char *gender;
    char *course;
    int *student_number;
    struct node *next;
    struct node *prev;
}*newnode, *firstPtr,*temp,student;

void insert_new(char *name, char *gender, char *course, int *number){


    newnode = (struct node*)malloc(sizeof (struct node));
    newnode->student_name = name;
    newnode->gender = gender;
    newnode->course = course;
    newnode->student_number = number;
    newnode->next = NULL;

    if (firstPtr == NULL)
    {
        firstPtr = newnode;
    }
    else
    {

        temp = firstPtr;
        while (temp->next != NULL)
        {
            temp = temp->next;
        }
        temp->next = newnode;
        firstPtr = temp;
    }
    printf("Insert success\n");
    printf("Press any key to go back main menu\n");
    getch();
}

void insert_last(){

}

void print_begin(){
    if (firstPtr == NULL)
        printf("List is empty\n");
    else
    {
        struct node *tempdisplay;
        tempdisplay = firstPtr;

        while (tempdisplay != NULL)
        {
            printf("%s\n", tempdisplay->student_name);
            printf("%s\n", tempdisplay->gender);
            printf("%s\n", tempdisplay->course);
            printf("%d\n", tempdisplay->student_number);
            tempdisplay = tempdisplay->next;
        }
    }
    printf("\n\nPress any key to go back main menu\n");
    getch();
}

void print_last(){

}

void remove_student(){

}

main()
{
    firstPtr=NULL;
    char name;
    char gender;
    char course;
    int number;
    int main_choice;
    do{
        printf("\n");
        printf("\n");
        printf("\n");
        printf("               1.Add a new student to the beginning\n");
        printf("               2.Add a new student to the end\n");
        printf("               3.Print out the entire list from the beginning\n");
        printf("               4.Print out the entire list from the end\n");
        printf("               5.Remove a student from the list\n");
        printf("               6.Quit the program\n");
        printf("\n\nEnter the number of the options\n");
        scanf("%d", &main_choice);

        switch (main_choice){

        case 1: {
                    
                    printf("Enter the name of the student\n");
                    scanf("%s", &name);
                    printf("Enter the gender of the student\n");
                    scanf("%s", &gender);
                    printf("Enter the course of the student\n");
                    scanf("%s", &course);
                    printf("Enter the number of the student\n");
                    scanf("%d", &number);
                    insert_new(name,gender,course,number);
        }break;
        case 2: insert_last(); break;
        case 3: print_begin(); break;
        case 4: print_last(); break;
        case 5: remove_student(); break;
        case 6:{
                   printf("\n\n\nThe program is closing...\n...\n");
                   return 0;
                   break;
        }
        }
        system("cls");
    } while (main_choice != 6);
}


[ 本帖最后由 chaicai333 于 2014-4-13 03:25 编辑 ]
搜索更多相关主题的帖子: 资料 course function 
2014-04-12 17:12
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
回复 2楼 xiaozi2013
换粗给你了~
2014-04-13 03:25
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
回复 5楼 ying8501
不好意思 那个我漏了改
请帮我看一下这段应该怎样写?
我觉得这样assign value应该不对吧?
程序代码:
void insert_new(char name[], char xgender[], char xcourse[], int number){
    newnode = NULL;
    newnode = (struct node*)malloc(sizeof (struct node));
    newnode->student_name[40] = name;
    newnode->gender[40] = xgender;
    newnode->course[40] = xcourse;
    newnode->student_number = number;
    newnode->next = NULL;


还有为什么我fgets(name,100,stdin); 这个不会走的?
我expect output会printf("Enter the name of the student\n";
然后fgets(name,100,stdin); 给user输入
可是他直接跳到printf("Enter the gender of the student\n";这边
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
    char student_name[40];
    char gender[40];
    char course[40];
    int student_number;
    struct node *next;
    struct node *prev;
}*newnode, *firstPtr,*temp,student;

void insert_last(){

}

void print_begin(){

    struct node *tempdisplay;
    tempdisplay = firstPtr;

    if (firstPtr == NULL)
        printf("List is empty\n");
    else
    {
        while (tempdisplay!= NULL)
        {
            printf("%s", tempdisplay->student_name);
            printf("%s", tempdisplay->gender);
            printf("%s", tempdisplay->course);
            printf("%d\n", tempdisplay->student_number);
            tempdisplay = tempdisplay->next;
        }
    }
    printf("\n\nPress any key to go back main menu\n");
    getch();
}

void print_last(){

}

void remove_student(){

}

void insert_new(char name[], char xgender[], char xcourse[], int number){
    newnode = NULL;
    newnode = (struct node*)malloc(sizeof (struct node));
    strcpy(newnode->student_name,name);
    strcpy(newnode->gender, xgender);
    strcpy(newnode->course, xcourse);
    newnode->student_number = number;
    newnode->next = NULL;

    if (firstPtr == NULL)
    {
        firstPtr = newnode;
    }
    else
    {
        while (firstPtr->next != NULL)
        {
            firstPtr = firstPtr->next;
        }
        firstPtr->next = newnode;
    }

    printf("Insert success\n");
    printf("Press any key to go back main menu\n");
    getch();
}

main()
{
    firstPtr=NULL;
    char name[40];
    char gender[40];
    char course[40];
    int number;
    int main_choice;

    do{
        printf("\n");
        printf("\n");
        printf("\n");
        printf("               1.Add a new student to the beginning\n");
        printf("               2.Add a new student to the end\n");
        printf("               3.Print out the entire list from the beginning\n");
        printf("               4.Print out the entire list from the end\n");
        printf("               5.Remove a student from the list\n");
        printf("               6.Quit the program\n");
        printf("\n\nEnter the number of the options\n");
        scanf("%d", &main_choice);

        switch (main_choice){

        case 1: {
                    printf("Enter the name of the student\n");
                    fgets(name,100,stdin);
                    printf("Enter the gender of the student\n");
                    fgets(gender,100,stdin);
                    printf("Enter the course of the student\n");
                    fgets(course,100,stdin);
                    printf("Enter the number of the student\n");
                    scanf("%d", &number);

                    insert_new(name,gender,course,number);
        }break;
        case 2: insert_last(); break;
        case 3: print_begin(); break;
        case 4: print_last(); break;
        case 5: remove_student(); break;
        case 6:{
                   printf("\n\n\nThe program is closing...\n...\n");
                   return 0;
                   break;
        }
        }
        system("cls");
    } while (main_choice != 6);
}


[ 本帖最后由 chaicai333 于 2014-4-13 18:22 编辑 ]
2014-04-13 17:24
快速回复:C,function不能用
数据加载中...
 
   



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

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