#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Unhappy Strcpy - problem!!!


    Hi,

    I tried looking for threads for strcpy specifically for my problem but i just can't find the specific answers. Anyway, here's my problem....

    I am trying to copy an array of string to my structure but i'm always getting an Unhandled Exception and points me to strcat.asm. Actually it is weird because in my program, it was not having the error not until i changed the value i passed. I tried several approach to test and debug why is it happening but it just keeps on giving the error.

    Below is a snippet of my code for your reference. I'm trying to copy a string to two differently declared structures. I hope someone could help me... ASAP! :(

    Code:
    ...
    typedef struct st_personal_info
    {
    	char	sName[51];
    	int	iAge;
    	char 	sAddress[501];
    	char	sBirthday[11];
    }ST_PERSONAL_INFO;
    
    typdef struct st_field_values
    {
    	char sField[6];
    	char sValue[51];
    } ST_FIELD_VALUES;
    
    ...
    
    int main()
    {
    	ST_PERSONAL_INFO *lst_personalInfo;
    	ST_FIELD_VALUES lst_fieldValues;
    	char lsToPass[11] = "MICHAEL";
    
    	strcpy(lst_fieldValues.sValue, lsToPass);
    	strcpy(lst_personalInfo->sName, lst_fieldValues.sValue);
    
    ...
    }
    I am having the exception at "strcpy(lst_personalInfo->sName, lst_fieldValues.sValue);" and I don't know why. Please help.

    Many thanks everyone!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Katy, Texas
    Posts
    495
    Rep Power
    199
    lst_personalInfo is a pointer to a struct st_personal_info, that you have never initialized to anything at all.
    Do you agree? Disagree? And remember, it's all about the reputation power...
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    cross-posting

    http://www.catb.org/~esr/faqs/smart-questions.html
    Read the bits about choosing a forum carefully, and the negative aspects of running around claiming it's urgent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Talking


    Originally Posted by TheOtherDino
    lst_personalInfo is a pointer to a struct st_personal_info, that you have never initialized to anything at all.
    Thanks TheOtherDino. You're right! i tried using malloc (suggested by CommonTater from another forum. haha.) and it's ok now. thanks again! really appreciate it! :D

IMN logo majestic logo threadwatch logo seochat tools logo