Hey guys I just started coding in C, so i'm no up to par with everything. I've been writing a program that deals with structs and linked lists, and I've run into an "imcompatible type in assignment" error and I can't see what's going on because I've been looking at this code for 1.5 hrs now. please help me. Thanks!
here's my func file
my headerCode:#include <stdio.h> #include <stdlib.h> #include "funcs.h" LIST_ELEM *add(LIST_ELEM *pHead,char type[],char name[], char title[], int year, int price, int size){ LIST_ELEM *new_elem = malloc(sizeof(LIST_ELEM)); new_elem->type = type; new_elem->name = name; new_elem->title = title; new_elem->year = year; new_elem->price = price; new_elem->size = size; return new_elem; }
and my main (its a noob program, but i'm a noob so its okCode:typedef struct list_elem { char type[5]; char name[50]; char title[50]; int year; int price; int size; struct list_elem *pNext; }LIST_ELEM; LIST_ELEM *add(LIST_ELEM *pHead,char type[],char name[], char title[], int year, int price, int size); int size(LIST_ELEM *phead); LIST_ELEM *find(LIST_ELEM *pHead, int value); void print(LIST_ELEM *pHead);)
Code:#include <stdio.h> #include <stdlib.h> #include "funcs.h" int main(void){ LIST_ELEM *pHead = NULL; char type[5]; char name[50]; char title[50]; int year; int price; int size; int choice; do { printf("What would you like to do? \n\n"); printf("0. Exit \n"); printf("1. Print books/cds. \n"); scanf("%d", &choice); switch(choice){ case 1: print(pHead); break; case 2: printf("Enter 'book' or 'cd' for type: \n"); scanf("%s", &type); printf("Enter name of author/artist: \n"); scanf("%s", &name); printf("Enter title: \n"); scanf("%s", &title); printf("Enter year published/released: \n"); scanf("%d", &year); printf("Enter price: \n"); scanf("%d", &price); printf("Size of book/cd: \n"); scanf("%d", &size); pHead = add(pHead,type,name,title,year,price,size); break; } }while(choice != 0); return 0; }
I know it has to do with the passing in of character string for my add() method, but I don't know what the right syntax is to get it to work. Thanks again!


)
