我有使用指针2层结构没有影响,形成一个链表,我创建了这些工种操作:声明与指针
typedef struct hashtag {
char *text;
int count;
} *Item;
typedef struct node {
Item item;
struct node *next;
} *link;
我在与所有的指针一对夫妇的问题相同的功能。
/* adds hashtag (Item Type) to linked list (Link Type) */
void add_hashtag(char *word){
int search_result, i;
for (i = 0; i < strlen(word); i++)
/* converts word to all lowercase before adding */
token[i]=tolower(*(token + i));
Item buffer = (Item) malloc(sizeof(struct hashtag));
strcpy(buffer->text,word);
/* Runs through the list to see if the hashtag was already added */
search_result = (search_hashtag(head, buffer));
if (search_result!=NULL){
/* Increase count (occurrence) of hashtag if it already exists (returns link type or NULL if not found) */
increase_hashtag_count(search_result);
}
/* Create new struct type hashtag */
new_hashtag(buffer);
}
警告:赋值时将指针整数,未作施放[-Wint转换] search_result =(search_hashtag(头,缓冲液));
警告:(!search_result = NULL)指针和整数 如果进行比较{
的tolower()
功能和search_result()
不与指针正常工作,而且我无法调试这一点。
编辑:tolower()
固定的,我误读的文档
[请参阅此讨论关于为什么不在'C'中投射'malloc()'和家族的返回值。](http://stackoverflow.com/q/605845/2173917)。 –
'int search_result'但它需要一个指针。 'strcpy(buffer-> text,word);':'buffer-> text'不分配。 – BLUEPIXY