The info_node structure I made has hourly_wage components and job_title of 25 characters. I have built print_list, add_node. Still working on find and delete. But I want to make sure my print list and add node works first. But it wont compile because in my add_node function I get error:"incompatible types in assignment of 'char*' to char[25]. I know I shouldn't post programs that don't compile but I'm stuck and really need some assistance.
Code:
#include<stdio.h>
#include<stdlib.h>
#define SENT -1
typedef struct info_node_s
{
char job_title[25];
double hourly_wage;
struct info_node_s *restp;
} info_node_t;
void print_list(info_node_t *n1_p);
void add_node(info_node_t **n1_p, char job_title, double hourly_wage);
/*void find_node(info_node_t **n1_p, char job_title);
void delete_node(info_node_t **n1_p, char job_title);
*/
main()
{
info_node_t *n1_p;
char choice, A, R, F, D, Q;
char job_title[25];
double hourly_wage;
n1_p = (info_node_t *)malloc(sizeof (info_node_t));
printf("Enter A(dd), R(emove), F(ind), D(isplay), or Q(uit)>");
scanf(" %c", &choice);
if(choice==A){
printf("Enter another job title \n");
scanf(" %s", &job_title);
printf("Enter another hourly wage \n");
scanf(" %.2f", &hourly_wage);
add_node(&n1_p, job_title, hourly_wage);
}
/* else if(choice==R){
printf("Enter job you want to delete \n");
scanf("%s", &job_title);
delete_node(n1_p,job_title);
}
else if(choice==F){
printf("Enter job you want to find \n");
scanf("%s", &job_title);
find_node(n1_p, job_title);
}*/
else if(choice==D){
print_list(n1_p);}
else if(choice==Q){
printf("Leaving the program\n");
}
else{
printf("Illegal choice, try again\n");}
System("pause");
return (0);
}
void add_node(info_node_t **n1_p, char job_title[25],double hourly_wage)
{
info_node_t *temp;
temp=*n1_p;
if(*n1_p==NULL)
{*n1_p=(info_node_t *)malloc(sizeof (info_node_t));
temp=*n1_p;}
else
{while((temp->restp)!=NULL)
{temp=temp->restp;}
temp->restp=(info_node_t *)malloc(sizeof (info_node_t));
temp=temp->restp;}
temp->job_title=job_title;
temp->hourly_wage=hourly_wage;
temp->restp=NULL;
}
/*
void delete_node(info_node_t **n1_p, char job_title)
{
}
void find_node(info_node_t **n1_p, char job_title)
{
}
*/
void print_list(info_node_t *n1_p)
{
if(n1_p==NULL)
{printf("\n");}
else {printf("%c , %.2lf ",n1_p->job_title,n1_p->hourly_wage);
print_list(n1_p->restp);}
}