943,919 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1512
  • C RSS
Oct 28th, 2005
0

What am I doing wrong?

Expand Post »
My darn code keeps crashing, what am I doing wrong? I have a class with the follwoing method:

  1. void BBSNode::AddToBuffer(char *buffer) {
  2. //strcat((char*)inputBuffer, (char*)buffer);
  3. sprintf("Got Data: %s\n", buffer);
  4. }

I'm calling the method like this:
  1. nodes[nodeID].AddToBuffer(sockBuffer);

sockBuffer was declared like ...
  1. char sockBuffer[IN_BUFFER_SIZE];

Now, when I run the program and it calls AddToBuffer it crashes with a Bus error.

How am I calling this method wrong?

I'm using XCode 2.0

Thanks!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005
Oct 28th, 2005
0

Re: What am I doing wrong?

I am retarted.

I realized I was using sprintf, not printf.

Duh! Thanks for your views everyone.
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005
Oct 28th, 2005
0

Re: What am I doing wrong?

Quote ...
sprintf("Got Data: %s\n", buffer);
The above is wrong. Was it just a posting error or is it really like that in your program ?
Quote ...
sprintf(InputBuffer, "Got Data: %s\n", buffer);
or
  1. strcpy(InputBuffer,"Got Data: ");
  2. strcat(InputBuffer,buffer);
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 28th, 2005
0

Re: What am I doing wrong?

I ment to do: printf, not sprintf.

Thanks.
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Type casting and type conversions
Next Thread in C Forum Timeline: help me on this power of 2





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC