Sprintf only sending last message.

I have two programs, one is a server and one is a client. It is a game of jackblack that is played on the client. In one of my functions DisplayCards();

void Blackjack::DisplayCards()
{
sprintf(buf,"Player 1 (house) has the two cards. ");
send(sd2,buf,sizeof(buf),0);

P1Cards[x] = NewCard();

sprintf(buf, "Card 1: %d", P1Cards[x]);
send(sd2,buf,sizeof(buf),0);

x++;

P1Cards[x] = NewCard();
/*
sprintf(buf, "Card 2: %d", P1Cards[x]);
send(sd2,buf,sizeof(buf),0);

for(int i=0; i<10; i++)
player1 += P1Cards[i];

sprintf(buf,"Player 1 total: %d", player1);
send(sd2,buf,sizeof(buf),0);

//Player 2 (user)

sprintf(buf,"\nPlayer 2 (you) have the two cards. ");
send(sd2,buf,sizeof(buf),0);

P2Cards[y] = NewCard();

sprintf(buf,"Card 1: %d", P2Cards[y]);
send(sd2,buf,sizeof(buf),0);

y++;

P2Cards[y] = NewCard();

sprintf(buf," Card 2: %d", P2Cards[y]);
send(sd2,buf,sizeof(buf),0);

for(int i=0; i<10; i++)
player2 += P2Cards[i];

sprintf(buf,"Player 2 total: %d",player2);
send(sd2,buf,sizeof(buf),0);
}

This is on the Server's side. the code to receive this on the client side is:

// display cards
for(int i=0;i<8;i++)
{
n = recv (sd, buf, sizeof (buf), 0);
cout << buf << endl;
y++;
}
//---------------------------
which just receives 8 messages, one at a time, and prints each one to the screen before it increments and receiving the next one.
For some reason i am only receiving the last message sent in the DisplayCards() function. ive tried sending 2 messages, and i only receive the second, if i send 3 messages i only receive the third. Any help is greatly appreciated.
Last edited on
Bump
Topic archived. No new replies allowed.