이것은 쉬운 링크 목록 문제라고 생각하지만 main() 함수에 input_info()를 추가하면 MSVC cl 컴파일러에서 다음과 같은 오류 메시지를 표시합니다.이상한 오류 메시지가 C에서 구조화 된 노드와 연결된 목록과 연결된
syntax error : missing ';' before 'type'
error C2065: 'first_ptr' : undeclared identifier
warning C4047: 'function' : 'struct linked_list *' differs in levels of indirection from 'int '
warning C4024: 'print_list' : different types for formal and actual parameter 1
나는 컴파일러가 다음과 같은 오류를 표시하는 이유를 모르겠다 ... 왜 MSVC 6.0 컴파일러가 나에게 이처럼 오류 메시지를주는 지 알게 해줘.
/*
*
* this program is a simple link list which will have add(),
* remove(), find(), and tihs link list will contains the student
* information.
*
*/
#include <stdlib.h>
#include <stdio.h>
//this ppl structure student holds student info
typedef struct
{
char *name;
int height;
int weight;
}ppl;
//this structure is the link list structure
typedef struct linked_list
{
ppl data;
struct linked_list *next_ptr;
} linked_list;
//this function will print the link list in a reversed order
void print_list(linked_list *a)
{
linked_list *llp=a;
while (llp!=NULL)
{
printf("name: %s, height: %d, weight: %d \n",llp->data.name,llp->data.height,llp->data.weight);
llp=llp->next_ptr;
}
}
//this function will add ppl info to the link list
void add_list(ppl a, linked_list **first_ptr)
{
//new node ptr
linked_list *new_node_ptr;
//create a structure for the item
new_node_ptr=malloc(sizeof(linked_list));
//store the item in the new element
new_node_ptr->data=a;
//make the first element of the list point to the new element
new_node_ptr->next_ptr=*first_ptr;
//the new lement is now the first element
*first_ptr=new_node_ptr;
}
void input_info(void)
{
printf("Please input the student info!\n");
}
int main()
{
ppl a={"Bla",125,11};
input_info();
//first node ptr
struct linked_list *first_ptr=NULL;
//add_list(a, &first_ptr);
printf("name: %s, height: %d, weight: %d \n",a.name,a.height,a.weight);
//print link list
print_list(first_ptr);
return 0;
}
일반적으로 'internal'구조체 이름과 typedef 이름에 다른 식별자를 지정합니다. typedef에서'struct linked_list'를 다른 것으로 변경하면 도움이됩니까? (모든 오류는'linked_list' 만 이해하지 못하는 것과 관련이 있습니다.) 오류를보고있는 행을 확인하면 일반적으로 도움이됩니다. – Rup
사실 MSVC IIRC에서 허용해서는 안되는'input_info()'다음에'struct linked_list * first_ptr'을 선언했습니다. C++가 아닌 C로 컴파일하고 있습니까? – Rup
어림짐작으로서, 유형이 비슷하지만 사용 방법과 방식이 다른 변수에 대해서는 정확히 같은 이름을 사용하지 마십시오.'linked_list 유형의 변수에'first_ptr' 이름을 사용하지 마십시오 **'또는'struct linked_list *', 등등. 너 자신을 혼란스럽게 할 뿐이다. 그들에게 더 정확한 이름을주십시오. –