sprintf outputting a char array

In my class we have a server and a client and we send information between the two. For this program is a memory game. The card game where you have 14 cards in front of you. 7 different cards, two copies of each and you flip two to see if they match if they do you keep them face up, that game. Anyways the server is the only thing that is allowed to have access to the functions so im trying to send the playing board to the client so it would output as:
x|x|x|x
x|x|x|x
x|x|x|x
x|x|x|x

i have tried numerous things and just can not figure out how to do it. The letters are stored in a two dimensional char array. Im just trying to send the char array.

temp_letter = C[i][j];
sprintf(buf,"%c", temp_letter);
send(sd2, buf, sizeof(buf), 0);


sprintf(buf,"%c", C[i][j]);
send(sd2, buf, sizeof(buf), 0);

Are just two things i have tried out of many. If anybody knows how to do this i would be very appreciative. If what i'm saying isn't clear i can paste the entire code and highlight the code that its stuck at. Currently it doesn't send anything only blank spaces. It compiles fine and doesn't crash when i run through it. It just doesn't send the Char array.
Bump
What to do in order to read the data depends on how you wrote it. So show these two functions.

It just doesn't send the Char array.
What makes you think so?
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (A[i][j] != 1)
{
sprintf(buf, "x");
send(sd2, buf, sizeof(buf), 0);
}
else
{
temp_letter = C[i][j];
printf(buf,"%c", temp_letter);
send(sd2, buf, sizeof(buf), 0);
}
}
}
This is one way with temp_letter being the char

for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (A[i][j] != 1)
{
sprintf(buf, "x");
send(sd2, buf, sizeof(buf), 0);
}
else
{
printf(buf,"%c", C[i][j]);
send(sd2, buf, sizeof(buf), 0);
}
}
}

Just trying to send the array.

The reason i say it just doesn't send the Char array is because it just outputs a bunch of new lines in place of where the letters should be and then continues with the rest of the program asking for which tile you would like to flip which is what immediately follows printing out the playing board.
Well, that's not much more. How is buf defined and how do you read it?

You send a c-string (which is actually a single character), but sizeof() isn't appropriate for that. Use strlen(buf) + 1.
buf is a char array with the ability to hold 100 characters inside of it. char buf[100];

n = recv (sd, buf, sizeof (buf), 0);
cout << buf << endl;

is how it is received.
With that few lines of code it's rather a guessing game...

You send single characters without the information where they were stored in the 2d array. I don't know what you're doing with this single characters on the receiver site, but that might be a problem.
You should see at least the characters.
Topic archived. No new replies allowed.