Hi, Im using a server and and a client, and the client can send messages to the server, but the messages gets cut when theres a whitespace.
Say I typed:
Hello my name is adam.
The server will catch it as: Hello
I think this has to do with cin, or the char[] method.
heres the client message code: -
-
char message[1000];
-
for(;;){
-
-
std::cout << "Message: ";
-
std::cin >> message;
-
if(strstr(message,"\\exit")){send(mysoc, "\\Disconnect", 1000, 0); break;}
-
send(mysoc, message,1000, 0);
-
}
-
Server catch code: - char buf[1000];
-
for(;;){
-
if((recv(clientsocket, buf, 1000, 0)) == -1)
-
{ message.write("!:Error recieving client message<br>\n"); break;}
-
else { message.write(buf);}
-
}
Can someone help me to get the client to send a full message.
7 2812
When you do 'cin >> buf' the istream will be read until a white space character
is read from the stream. Use the streams' getline() method instead if you want
to read an entire line from the stream.
kind regards,
Jos
Thanks, what header, and class does it come under?
Thanks, what header, and class does it come under?
The same header file and class you're using already; just a different function.
Here's a nice online reference.
kind regards,
Jos
Ok, Thanks for all your help, works smooothly.
<iostream>. Check reference.
Maybe we should get rid of those old stickies and post just one new one that
mentions this (and other) useful links. Similar to what I did in the Java forum ...
kind regards,
Jos
Maybe we should get rid of those old stickies and post just one new one that
mentions this (and other) useful links. Similar to what I did in the Java forum ...
kind regards,
Jos
There's an article in the how-tos with C/C++ links but I think some of them are a little outdated, and probably few people check there. So yes, I think that's a great idea, so long as it's updated now and then.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Don |
last post by:
Can't figure this one out. The "validate" function below checks to make sure the field "names" is
not null. "validate" actually calls "isEmpty", which scans the field.
Here's the situation. ...
|
by: Sathyaish |
last post by:
I noticed that gets() reads into the buffer even if the you've not
allocated enough memory. For instance, if you do:
char *str=(char*)malloc(sizeof(char));
printf("Enter something about...
|
by: arkobose |
last post by:
hey everyone!
i have this little problem. consider the following declaration:
char *array = {"wilson", "string of any size", "etc", "input"};
this is a common data structure used to store...
|
by: yaniv.dg |
last post by:
hi all,
i'm bumping into smething very starnge
its very simple code but from some reason the program is acting strange
this is my code:
#include<stdio.h>
#include<conio.h>
void main(void)
{...
|
by: william |
last post by:
I wonder how 'main(int argc, char ** argv)' is implemented? How
does it get
the string literals separated by whitespace from the stdin stream?
And is there any difference between 'char**' and...
|
by: Alan |
last post by:
How do I convert the type const char* to type char*?
I have an input string ("input_string") of class string. I need
to convert this to type char* in order to use it in a call to the
strtok()...
|
by: kudruu |
last post by:
Hello,
I am having a problem in Microsoft Visual C++ with some code I have
written (I am a bit of a novice so I appologize if this is a very
mundane problem).
This is a segment from one of the...
|
by: David Mathog |
last post by:
Apologies if this is in the FAQ. I looked, but didn't find it.
In a particular program the input read from a file is supposed to be:
+ 100 200 name1
- 101 201 name2
It is parsed by reading...
|
by: FerrisUML |
last post by:
Hello everyone! I new to C and am having the following problem. In
the below program, the last scanf is being ignored and the program
exits. Can anyone see anything that im doing wrong? Thanks...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |