![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Feb 2008
Posts: 17
| 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().");
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;
}
}
PS: I use Eclipse on Win. |
| ferenczi is offline | |
| | #2 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| fscanf with %s cannot read a string with spaces in it. If you want to read a string with spaces in it, fscanf is not for you; maybe use fgets instead. (And do you really intend to read from stdout?) |
| tabstop is offline | |
| | #3 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Not that it makes any difference to the question you are asking, but did you know that: Code: 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; Code: case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': k++; break; -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #4 |
| Registered User Join Date: Feb 2008
Posts: 17
| ! @tabstop: fscan with stdout is a typing error (thanks for telling me). I've used fgets() and works fine (thanks). @matsp: thank you for your tip about writing code: I've corrected the switch. |
| ferenczi is offline | |
![]() |
| Tags |
| recvfrom(), sendto(), strings |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hook sendto and recvfrom | brietje698 | Networking/Device Communication | 4 | 12-10-2007 03:58 AM |
| Socket Datagram info sendto(), recvfrom() | siluro | C Programming | 1 | 02-20-2005 12:10 PM |