【发布时间】:2018-05-04 06:12:53
【问题描述】:
如果ListofChar 是指向Char 的指针(不要与char 混淆),它代表struct charact,
那么void report(ListofChar chars)中的ListofChar chars是什么意思呢?chars 是否只代表指针ListofChar?
#include <stdio.h>
#include <stlib.h>
struct charact {
char ch;
int occurs;
struct charact *next;
};
typedef struct charact Char;
typedef Char * ListofChar;
typedef Char * CharNode_ptr;
void letters(char name[50], ListofChar * chars_ptr);
void report(ListofChar chars);
Char * createnode(char ch);
int main() {
char name[50];
ListofChar chars = NULL;
scanf("%s", name);
letters(name, &chars);
report(chars);
return 0;
}
Char * createnode(char ch) {
CharNode_ptr newnode_ptr ;
newnode_ptr = malloc(sizeof (Char));
newnode_ptr -> ch = ch;
newnode_ptr -> occurs = 0;
newnode_ptr -> next = NULL;
return newnode_ptr;
}
【问题讨论】:
-
tip : 避免对指针进行 typedefs,它会为您节省一些未来的麻烦。