I'm debugging an assignment due very soon, please help ASAP.
The error is:
Assignment makes pointer from integer without a cast.
So, apparently add_group returns an int, yet the return type is char *
this is the block of code that calls the function which returns a char * pointer:
buffer is delcared as this -------> char *buffer;
Code:
} else if (strcmp(cmd_argv[0], "add_group") == 0 && cmd_argc == 2) {
buffer = add_group(group_list_addr, cmd_argv[1]);
printf("%s", buf);
This is the block of code that is add_group:
Code:
char *add_group(Group **group_list_ptr, const char *group_name) {
if (find_group(*group_list_ptr, group_name) == NULL) {
//malloc space for new group
Group *newgrp;
char *groupSucc;
char *groupFail;
if ((groupSucc = malloc(sizeof(group_name) + 21)) == NULL) {
perror("Error allocating space for add_group success message");
exit(1);
strcpy(groupSucc, "Group ");
strcat(groupSucc, group_name);
strcat(groupSucc, " added");
if ((newgrp = malloc(sizeof(Group))) == NULL) {
perror("Error allocating space for new Group");
exit(1);
}
// set the fields of the new group node
// first allocate space for the name
int needed_space = strlen(group_name) + 1;
if (( newgrp->name = malloc(needed_space)) == NULL) {
perror("Error allocating space for new Group name");
exit(1);
}
strncpy(newgrp->name, group_name, needed_space);
newgrp->users = NULL;
newgrp->xcts = NULL;
newgrp->next = NULL;
// Need to insert into the end of the list not the front
if (*group_list_ptr == NULL) {
// set new head to this new group -- the list was previously empty
*group_list_ptr = newgrp;
return groupSucc;
} else {
// walk along the list until we find the currently last group
Group * current = *group_list_ptr;
while (current->next != NULL) {
current = current->next;
}
// now current should be the last group
current->next = newgrp;
return groupSucc;
}
} else {
// group EXISTS
if ((groupFail = malloc(sizeof(group_name) + 21)) == NULL) {
perror("Error allocating space for add_group failure message");
exit(1);
}
strcpy(groupFail, "Group ");
strcat(groupFail, group_name);
strcat(groupFail, " already exists");
return groupFail;
}
}