-
Help!
Im working on aprogram for entries the struct is:
Code:
struct entry
{
char name[STR_SIZE];
char email[STR_SIZE];
char phone[STR_SIZE];
};
i need to do what is in comments how am i doing?
ENTRY *create_Entry(char *name, char *email, char *phone)
{
/* TO DO: Allocate memory, assign values to fields, return address. */
ENTRY *ptr;
ptr = (ENTRY *)malloc(sizeof(ENTRY));
ptr -> name = NULL;
ptr -> email = NULL;
ptr -> phone = NULL;
return ptr;
}
-
You don't need to allocate any memory other than for the ptr because name, email, and phone are all arrays, not pointers. You also don't need to typecast malloc.
Quzah.
-
How do i do this setter?
Im stuck at this anyone help?
Code:
/* This function sets the name of the entry with the given value. */
void setName_Entry(ENTRY *self, char *name)
{
/* TO DO: Assign name to corresponding field. */
char *ptr;
for (ptr = name; *ptr != '\0'; ptr++){
*self -> name = *ptr;
}
}
-
You don't have pointers, so stop trying to assign as if they were. You need to read: Arrays and Pointers
You have arrays. You either need to loop through them assigning one value at a time, or you need to use a function that does that for you (ie: strcpy).
Quzah.
-
Thanks very much me and my friend finally did the program of entries now we are stuck on a phonebook app ^^