I have 2 structs using pointers to form a linked list and I'm creating operations that work over these types:
typedef struct hashtag {
char *text;
int count;
} *Item;
typedef struct node {
Item item;
struct node *next;
} *link;
I'm having a couple issues with pointers all on the same function.
/* 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);
}
warning: assignment makes integer from pointer without a cast [-Wint-conversion] search_result = (search_hashtag(head, buffer));
warning: comparison between pointer and integer if (search_result!=NULL){
The tolower()
function and search_result()
are not working with pointers correctly and I'm having trouble debugging this.
edit: tolower()
fixed, I misread the documentation