Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

minor bug with output

Posted on 2004-11-15
5
Medium Priority
?
309 Views
Last Modified: 2010-04-17
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

0
Comment
Question by:WackoMike
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Santino_k earned 200 total points
ID: 12590864
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
 

Author Comment

by:WackoMike
ID: 12590958
Tried doing that...did not work for me. :-/
0
 

Author Comment

by:WackoMike
ID: 12590968
ok fixed it instead of using

site = "url";

i used

strcat(site,"url");
0
 

Author Comment

by:WackoMike
ID: 12592081
this seems to only cause more memory errors down the road...
0
 
LVL 3

Expert Comment

by:Santino_k
ID: 12601054
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Progress
Loops Section Overview

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question