minor bug with output

char* site;
site = "http://www.somesite.com/file.php?arg=1&arg2=hrm";

strcat(site,Realm());
            
      
MessageBox(0,site,"test",1);



char*Realm()
{

      char* realm;
      int one, two = 0;
      one = rand(); // this gives player one a dice roll
    two = rand(); // this gives player two a dice roll
          if (one < two)
            {
               realm = "UsEast";
        }
        else
            {
                  realm = "UsWest";
        }


      return realm;

}



the problem is that it was making my messagebox title the last part of the realm like ast or est

WackoMikeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Santino_kCommented:
Just make the following changes, I think it will work for you. You didn't allocate proper memory to store your strings. Check the code I have changed below

//allocate enough memory to char* site

char* site=(char *)malloc(sizeof(char)*256);

site = "http://www.somesite.com/file.php?arg=1&arg2=hrm";

     .......................

char*Realm()
{
     //allocate enough memory to char* realm
     char* realm=(char *)malloc(sizeof(char)*25);;
     .......................
   
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WackoMikeAuthor Commented:
Tried doing that...did not work for me. :-/
0
WackoMikeAuthor Commented:
ok fixed it instead of using

site = "url";

i used

strcat(site,"url");
0
WackoMikeAuthor Commented:
this seems to only cause more memory errors down the road...
0
Santino_kCommented:
I am sorry I missed out the strcat(...) after memory allocation.
You allocate memory and then do a strcat(...). This is ideal way to do it.
Thanks for points :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.