C 프로그래밍에 익숙하지 않습니다. 누구든지 다음 프로그램에 무엇이 잘못되었는지 말해 주시겠습니까? process_list 0에 기록 된 패스로c 포인터를 가리키는 포인터 또는 함수를 가리키는 포인터
Person_t *p_list=0;
...
process_list(count, &p_list);
코드를 한 다음, 당신은 :
typedef struct Person_s
{
int age;
char name[40];
} Person_t;
int process_list(int *countReturned, Person_t **p_list)
{
Person_t *rowPtr=0;
//the actual program will fethc data from DB
int count =1;
if(!((*p_list) = (Person_t *) malloc(sizeof(Person_t))))
{
return -1;
}
rowPtr = *p_list;
rowPtr[count-1].age =19;
strcpy(rowPtr[count-1].name,"Prince Dastan");
*countReturned = count;
return 0;
}
int main(int argc, char *argv[])
{
Person_t *tmpPerson=0;
Person_t **p_list=0;
int *count=0;
int i;
process_list(count,p_list);
tmpPerson = *p_list;
for(i=0; i< *count; i++)
{
printf("Name: %s , age: %d\n",tmpPerson->name,tmpPerson->age);
tmpPerson++;
}
//free(tmpPerson);
return 0;
}
코드 검토를 원하십니까? 아니면 특정 오류가 있습니까? 그렇다면 문제는 무엇입니까? –