저는이 프로젝트를 하루 이상 진행해 왔으며 정말 혼란 스럽습니다. 나는 누군가가 이것을 이해하도록 도와주기를기도합니다. 함수 insertItemList
에 문제가 있습니다. 테스트 파일에 String
을 linked list
으로 가져 오는 방법을 모르겠습니다. 이건 숙제 야. 이 프로젝트는 이것보다 훨씬 큽니다. 그러나 나는 도움이 필요한 것만으로 그것을 어리석게 만들었습니다. 아무도 내가 뭘 잘못하고 있는지 알아?링크 된 목록에 문자열을 삽입하는 것에 대해 매우 혼란스러워합니다.
List.h
#ifndef _list_h
#define _list_h
/*
* Defines a single list item.
*/
typedef char *ListItemT;
/*
* Defines ListP to be a POINTER to a list struct.
* (Define the list struct in the (.c) file.
*/
typedef struct ListT *ListP;
/*
* Returns a pointer to a new empty list.
* You may implement this list as a singly or doubly
* linked list.
*/
ListP newList();
/*
* Creates a new node, inserts the item into the
* new node and inserts the new node into the list
* after the current node.
* Current in then moved to the newly inserted node.
* NOTE: Impossible to insert at head of list.
*/
void insertItemList(ListP, ListItemT);
#endif
List.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "List.h"
struct ListT
{
char INFO[20];
struct ListT *Next;
}*Head;
/*
* Returns a pointer to a new empty list.
* You may implement this list as a singly or doubly
* linked list.
*/
ListP newList()
{
// allocate memory for new list
struct ListT *newnode = malloc(sizeof(struct ListT));
return newnode;
}
/*
* Creates a new node, inserts the item into the
* new node and inserts the new node into the list
* after the current node.
* Current in then moved to the newly inserted node.
* NOTE: Impossible to insert at head of list.
*/
//where I'm having trouble
void insertItemList(ListP LOC, ListItemT DATA)
{
struct ListT *temp;
temp=(struct ListT *)malloc(sizeof(struct ListT));
strcpy(temp->INFO, DATA);
}
ListTest.c
#include <stdio.h>
#include <string.h>
#include "List.h"
int main()
{
// Create two lists
ListP list1 = newList();
ListP list2 = newList();
printf("\nList Creation Successful!\n");
// Insert one name into the first list
insertItemList(list1, "Alice"); //Ive never seen a parameter like this before.
}
** 특별히 ** 귀하의 질문은 무엇입니까? – templatetypedef