Hello!
I have the following problem:
My Client waits for a string and sends it to a Server:
Code:
memset(&echoString2, 0, sizeof(echoString2));
fprintf(stdout,"\nInput a string: ");
do {
fscanf(stdout, "%s", echoString2);
} while (strlen(echoString) > MAX);
echoStringLen = strlen(echoString2);
if (sendto(sock, echoString2, echoStringLen, 0, (struct sockaddr *)
&echoServAddr, sizeof(echoServAddr)) != echoStringLen)
printError("\nError in sendto().");
The Server receives this string and counts vowels:
Code:
memset(&echoBuffer, 0, sizeof(echoBuffer));
if ((recvMsgSize = recvfrom(sock, echoBuffer, MAX, 0,
(struct sockaddr *) &echoClntAddr, &cliAddrLen)) < 0)
printError("\nrecvfrom() failed.");
fprintf(stdout, "Received string: %s", echoBuffer);
for (i = 0; i < strlen(echoBuffer); i++)
{
switch(echoBuffer[i]) {
case 'a': k++; break;
case 'A': k++; break;
case 'e': k++; break;
case 'E': k++; break;
case 'i': k++; break;
case 'I': k++; break;
case 'o': k++; break;
case 'O': k++; break;
case 'u': k++; break;
case 'U': k++; break;
}
}
But I've noted, when I send a a string with blanks, the receivfrom() stops to the first word and counts the vowels of this one. I don't know why. Any idea?
PS: I use Eclipse on Win.