私のプログラムの作り方を理解できません。プログラムは、ユーザに番号を入力して印刷するように要求する。リンクされたリストを使用して値を保存します。しかし、それを働かせることができない、助けを必要とする 。私はあなたがパラメータを渡しているが、それらはまた、出力パラメータであり、あなたのinsert(head, current);
機能で参照を引数として渡す関数への参照を渡す方法
#ifndef STRUCTURE_H_
#define STRUCTURE_H_
struct intNode
{
int value;
struct intNode *next;
};
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "structure.h"
#define commandLength 6
#define initSize 100
void insert(struct intNode *head, struct intNode *current);
void print(struct intNode *head);
int main()
{
char command[commandLength];
struct intNode *head = NULL;
struct intNode *current = NULL;
printf("Enter a command from the following list of commands:\n\n"
"insert - to add a number to the list;\n"
"print - to print out the list;\n"
"exit - to terminate the program;\n\n"
"Enter your command:\n");
while (strcmp(command, "exit") != 0)
{
scanf("%s",command);
if(strcmp(command,"insert") == 0)
{insert(head, current);}
else if(strcmp(command, "print") == 0)
{print(head);}
else if(strcmp(command, "exit") == 0)
{printf("\nThe program has been terminated.");}
else
{printf("Error: unknown request '%s'\n", command);}
}//end of while
}//end of main
void insert(struct intNode *head, struct intNode *current)
{
struct intNode *node;
node = (struct intNode *) malloc(sizeof(struct intNode));
printf("enter a number:");
scanf("%d",&node->value);
if(head == NULL)
{
head = node;
}
else
{
if(head->next == NULL)
{
head->next = node;
current = node;
}else{
printf("%d ",current->value);
current->next = node;
current = node;
}
}
}//end of insert
void print(struct intNode *head)
{
struct intNode *temp;
temp = head;
while(temp != NULL)
{
printf("%d ",temp->value);
temp = temp->next;
}
}//end of print
ありがとうございました!!!! –