Hello everyone ,
A quick question here about an error I seem to get around my code a lot , the program crashes at several locations with run time error 0xC0000005 .
This happens to me at the following function , which creates a user`s profile and puts it in a database later :
Code:
/*
The following function will create a profile in the linked list.
Basically , create nodes on "top" of the head node in the linked list .
*/
void createProfile(char *userMail,char *userPass,short age,char *firstName,char *lastName,char *country)
{
char userName[MAX_NAME_LENGTH]; //Will save the users - user name (the part without @gmail.com).
Profiles *new_profile=(Profiles *)malloc(sizeof(Profiles *));
if(new_profile!=NULL) //Check if not NULL , we can only continue if the malloc operation was successfull.
{
strcpy(new_profile->userMail,userMail);
strcpy(new_profile->password,userPass);
new_profile->age=age;
strcpy(new_profile->firstName,firstName);
strcpy(new_profile->lastName,lastName);
strcpy(new_profile->country,country);
p_heap[numberOfProfiles]=new_profile;
p_heap[numberOfProfiles]->signedIn=0;
getUser(userMail,userName);
strcpy(new_profile->userName,userName);
}//if
else
createProfile(userMail,userPass,age,firstName,lastName,country); //If the malloc operation failed - try again.
return;
}//createProfile
Where`s Profile is a struct :
Code:
typedef struct Profile {
char userMail[MAX_MAIL_LENGTH]; //uses the MAX_MAIL_LENGTH macro (40 as for now) for the mail of ones profile , acts as user name . I believe that this is enough.
char password[MAX_PASS_LENGTH]; //uses the MAX_PASS_LENGTH macro (8 as requested) , this will be a string that holds up to 8 chars and one for '\0' .
char firstName[MAX_NAME_LENGTH]; //use the MAX_NAME_LENGTH (20 as for now) for the first name , I think it is enough , could be raised if I will differ my thoughts.
char lastName[MAX_NAME_LENGTH]; //^ ditto .
char country[MAX_COUNTRY_LENGTH]; //The country will be validated from a list that will be saved in a file.
short age; //Saving as much memory as we can .
char phone[MAX_PHONE_LENGTH]; //Uses the MAX_PHONE_LENGTH macro (11 = 10 + 1 for '\0' for now) , will be used to save the phone number .
enum Smartphone{ //An enum denoting if one has a smartphone or has not , this for suggesting an app , which we wont really have , yet again ..
noPhone=0,yesPhone} Smartphone;
enum Sinefield_or_friends{ //An enum denoting if one is prefering sinefield , or rather friends as a tv show .
sinefield=0,friends} S_or_f;
enum Dogs_or_cats{ //An enum denoting if one is prefering dogs or cats as a pet .
dogs=0,cats} D_or_c;
enum Jackey_got_an_sms{ //An enum denoting if one has sent Jackie from the show "The big brother" an SMS text for to win the million NIS .
noSms=0,yesSms} J_got_sms;
short signedIn; //How many times the user have logged in.
short filledAdditionalInfo; //If one has filled additional information (boolean & phone number)
char userName[MAX_NAME_LENGTH]; //This is the user name (the part without @gmail.com).
short pals[MAX_PROFILES]; //Will save indexes of profiles which are pals with the current profile .
short wantToBePals[MAX_PROFILES]; //Will save indexes of profiles which would like to be pals with the current profile .
short blockedPals[MAX_PROFILES]; //Will save indexes of profiles which are blocked .
//To be done - dates .
} Profiles;
If I copy this to a clean code (just the struct , this function and main) it works flawlessly , but in my code it crashes on the second time
I call the creatProfile(...) function .
When I checked it - it crashes at the allocation point :
Profiles *new_profile=(Profiles *)malloc(sizeof(Profiles *));
Tried using calloc instead , same problem .
This really drives me mad , I don`t know what and how to fix it .
Any help would be extremely appreciated ,
Thanks ,
Danny .