473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a simple question

Hello,

how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a char and
give every part to a different variable. but i don't need that.

char buf[2000];
scanf("%s",char );
printf("%s",buf );

if i type "ha ha", it prints back "ha", but i want "ha ha".

Can please somebody help me
Jul 19 '05 #1
9 3418
you can either use gets() or the cin object.

Ali R.

"R.Neeser" <rn*****@gmx.ch > wrote in message
news:3f******** @news.tiscaline t.ch...
Hello,

how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a char and give every part to a different variable. but i don't need that.

char buf[2000];
scanf("%s",char );
printf("%s",buf );

if i type "ha ha", it prints back "ha", but i want "ha ha".

Can please somebody help me

Jul 19 '05 #2
"R.Neeser" <rn*****@gmx.ch > wrote...
how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a char and give every part to a different variable. but i don't need that.

char buf[2000];
scanf("%s",char );
printf("%s",buf );

if i type "ha ha", it prints back "ha", but i want "ha ha".


Try using 'getline' member function:

char buf[2000] = {0};
std::cin.getlin e(buf, 1999);

Victor

Jul 19 '05 #3
> Try using 'getline' member function:

char buf[2000] = {0};
std::cin.getlin e(buf, 1999);

Victor


Thank you, works very well
Jul 19 '05 #4
On Wed, 05 Nov 2003 19:15:00 GMT, "Ali R." <no****@company .com> wrote
in comp.lang.c++:

1. Don't top post.
you can either use gets() or the cin object.
2. Don't post dangerous rubbish. If you do not know enough not to
recommend or ever use gets(), the single most dangerous function in
the entire C or C++ standard library, you are totally unqualified to
give advice to anyone about programming in either of those languages.

3. Don't top post.

Ali R.

"R.Neeser" <rn*****@gmx.ch > wrote in message
news:3f******** @news.tiscaline t.ch...
Hello,

how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a char

and
give every part to a different variable. but i don't need that.

char buf[2000];
scanf("%s",char );
printf("%s",buf );

if i type "ha ha", it prints back "ha", but i want "ha ha".

Can please somebody help me


Jul 19 '05 #5
First of all I didn't top post!!! Sue me if my server takes a while to post
the message. You are so fucking rude.
What's wrong with gets(). How is gets any more dangarous then the scanf that
the guy was using? You can't pass a buffer size to scanf either. If the
question doesn't involve c++ why confuse the guy with a c++ class. If you
have noticed I said "or use the cin object"! If he knows what cin is then he
would use it if he doesn't then he will ask what the heck is cin and then I
would explane how to use it and how to include it!
I have 13 years of C++, and I teach C++.

Ali R.

"Jack Klein" <ja*******@spam cop.net> wrote in message
news:m9******** *************** *********@4ax.c om...
On Wed, 05 Nov 2003 19:15:00 GMT, "Ali R." <no****@company .com> wrote
in comp.lang.c++:

1. Don't top post.
you can either use gets() or the cin object.


2. Don't post dangerous rubbish. If you do not know enough not to
recommend or ever use gets(), the single most dangerous function in
the entire C or C++ standard library, you are totally unqualified to
give advice to anyone about programming in either of those languages.

3. Don't top post.

Ali R.

"R.Neeser" <rn*****@gmx.ch > wrote in message
news:3f******** @news.tiscaline t.ch...
Hello,

how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a
char and
give every part to a different variable. but i don't need that.

char buf[2000];
scanf("%s",char );
printf("%s",buf );

if i type "ha ha", it prints back "ha", but i want "ha ha".

Can please somebody help me

Jul 19 '05 #6


"Ali R." wrote:

First of all I didn't top post!!!
You did it again!
Seems like you don't know what top posting is.

Top posting means: you put your reply at the top of the thing
you are replying to.

Please don't do it. Put your reply beneath the text you are replying
to, if necc. embedd your reply in the text you are replying to, just
as I am doing it now.
Sue me if my server takes a while to post
the message. You are so fucking rude.
This has nothing to do with top posting.
What's wrong with gets().
There is no way to use it in a safe manner.
Look at the arguments to gets(). You have no way to tell gets()
how large the buffer is, you are passing to gets(). Eg. you
pass gets() a buffer which can hold 20 characters, but your user
enters 40 characters. Kaboom.

fget() on the other hand doesn't have that problem.
How is gets any more dangarous then the scanf that
the guy was using? You can't pass a buffer size to scanf either.
Right

If you want to recommend something better then gets or scanf, then start
with a combination of fgets() and sscanf(). Since the OP wanted to read
an enitre line of input, fgets() alone would be the choice.
If the
question doesn't involve c++ why confuse the guy with a c++ class. If you
have noticed I said "or use the cin object"! If he knows what cin is then he
would use
How?
What the user wanted to do with cin, is call the function getline. Either
the member function version or (in combination with std::string) the
standalone version. In any way, just mentioning 'cin' hasn't helped him
in any way. Just like saying: Use stdin will not help him in any way
if he is programming in C.
it if he doesn't then he will ask what the heck is cin and then I
would explane how to use it and how to include it!
I have 13 years of C++, and I teach C++.


But then you shouldn't recommend gets(). Never!

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 19 '05 #7


Karl Heinz Buchegger wrote:


[snip]
What's wrong with gets().


There is no way to use it in a safe manner.
Look at the arguments to gets(). You have no way to tell gets()
how large the buffer is, you are passing to gets(). Eg. you
pass gets() a buffer which can hold 20 characters, but your user
enters 40 characters. Kaboom.

fget() on the other hand doesn't have that problem.


obvious typo, must read: fgets() on the other ...

[snip]

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 19 '05 #8
In article <Ty************ ****@newssvr22. news.prodigy.co m>,
no****@company. com says...
First of all I didn't top post!!!
Yes, you did. Top-posting is when you put your reply before what you're
following up to. When your text comes before that quoted text of the
post to which you're following up, that's top-posting.

[ ... ]
What's wrong with gets().
It's dangerous because you can't limit the amount of text it will read
in.
How is gets any more dangarous then the scanf that
the guy was using? You can't pass a buffer size to scanf either.
Quite the contrary -- you most certainly CAN pass a buffer size of
scanf. A typical, reasonably safe use of scanf would look something
like this:

char buffer[50];

scanf("%49[^\n] ", buffer);

Of course, you can use similar capabilities (including the buffer-size
limit) with fscanf, sscanf, etc.). I'd also note that while the use of
scanf above is quite safe, it's possible that its effects will confuse
the user -- depending on the situation, something like this:

scanf("%49[^\n]%*c", buffer);

might be preferable.
If the
question doesn't involve c++ why confuse the guy with a c++ class.
If it had been specified that the desired language was C, that would
rule out use of cin. I see no such limitation in the subject or
original post. In any case, you were the one who originally brought up
the possibility of using cin.
If you
have noticed I said "or use the cin object"! If he knows what cin is then he
would use it if he doesn't then he will ask what the heck is cin and then I
would explane how to use it and how to include it!
Saying "you can use the cin object" is NOT really an answer to the
original question at all. Use of cin vs. stdin is orthogonal to the
original question.
I have 13 years of C++, and I teach C++.


What exactly does "I have 13 years of C++" mean?

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #9
In article <3f********@new s.tiscalinet.ch >, rn*****@gmx.ch says...
Hello,

how do i get an keyboard input from the consol, WITH THE Space char?
scnaf and all the other function divide the input string on such a char


If you use scanf with the %s conversion, THEN it splits input at
whitespace, but if you use it with %[^\n], it will read up to a newline
in the input. Alternatively, you might want to use fgets, which is
tailored specifically for reading complete lines of text.

Note that if you use fgets to read a line of text, the newline that
terminates the input line will normally be retained in the string that's
read in (if it's not there, it means the line contained more text than
the maximum you told fgets to read).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3703
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example program #include <list>
1
3432
by: Proteus | last post by:
Any help appreciated on a small perl project I need to write for educator/teaching purposes. I have not programmed perl for some time, need to get up to speed, maybe some kind souls hrere will help me on this project? It looks to be a simple project, and I will start relearning pearl, but any help appreciated! I need to read and parse a simple text file (INPUT) containing multiple choice quiz questions (with titles) and answers, and...
2
5031
by: Raskolnikow | last post by:
Hi! I have a very simple problem with itoa() or the localtime(...). Sorry, if it is too simple, I don't have a proper example. Please have a look at the comments. struct tm *systime; time_t currentTime; char day; char month;
3
2168
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how can I programmatically select a node Thanks in Advanc Peter
7
2291
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request that page like http://machinename/dir1/hellp.aspx instead of running that page it starts downloding ...whats missing here ....why the aspx engine not running the page....
4
118819
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a character into a number?????? In Oracle, it is:
14
2990
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
30
3552
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
2142
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http:// wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
17
5826
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /* Simple Thread Object ______________________________________________________________*/ #include <pthread.h> extern "C" void* thread_entry(void*);
0
9699
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.