I'm writing a code to manipulate a linked list. But It won't compile because on line 36 i'm making an integer from a pointer without a cast. I'm not sure why this is happening. But it's affecting my function "Ins" which puts new characters into my list. Let me know what you think.
Please ignore functions del, fde, pst, prl, pcr, ppr, and psu. I haven't gotten to those yet, they shouldn't get in the way. Thanks
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MIN_LENGTH 4
#define MAX_LENGTH 11
struct node{
char list;
int count;
struct node *next;
};
typedef struct node Node;
typedef Node *ListNode;
void ins(ListNode *ptr, char value);
int main(void){
ListNode startPtr = NULL;
char com[MIN_LENGTH];
char cho[MAX_LENGTH];
while(strcmp(com, "end") != 0){
printf("Command? ");
scanf("%s", &com);
if(strcmp(com, "ins") == 0){
scanf("%s", &cho);
ins(&startPtr, cho);
printf("%s", cho);
}
else if(strcmp(com, "del") == 0){
// del();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "fde") == 0){
// fde();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "pst") == 0){
// pst();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "prl") == 0){
// prl();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "pcr") == 0){
// pcr();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "ppr") == 0){
// ppr();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strcmp(com, "psu") == 0){
// psu();
scanf("%s", &cho);
printf("%s\n", cho);
}
else if(strlen(com) >= 4 || strlen(com) < 3){
printf("You have entered an incorrect command.\n");
}
}
}
void ins(ListNode *ptr, char value){
ListNode newPtr;
ListNode prevPtr;
ListNode currPtr;
newPtr = (struct node*) malloc(sizeof(Node));
if(newPtr != NULL){
newPtr->list = value;
newPtr->next = NULL;
prevPtr = NULL;
currPtr = *ptr;
while(currPtr != NULL && value > currPtr-> list){
prevPtr = currPtr;
currPtr = currPtr->next;
}
if(prevPtr == NULL){
newPtr->next = *ptr;
*ptr = newPtr;
}
else{
prevPtr->next = newPtr;
newPtr->next = currPtr;
}
}
else{
printf("No memory available\n");
}
}
void del(){
}
void fde(){
}
void pst(){
}
void prl(){
}
void pcr(){
}
void ppr(){
}
void psu(){
}