473,881 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any way to take a word as input from stdin ?

I searched the c.l.c archives provided by Google as Google Groups with
"word input" as the key words and did not come up with anything good.
C++ has std::string for taking a word as input from stdin. C takes input
in 2 ways:

1) as a character, etchar()
2) as a whole line, fgets()
as C programmer, are we supposed to create a get_word function everytime
when we need a words as input from stdin ( e.g. terminal)
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming

Sep 10 '08
209 8919
On Sep 12, 1:32 pm, arnuld <sunr...@invali d.addresswrote:
On Fri, 12 Sep 2008 12:18:27 +0200, Richard wrote:
vipps...@gmail. com writes:
On Sep 12, 10:12 am, arnuld <sunr...@invali d.addresswrote:
On Thu, 11 Sep 2008 12:42:13 +0000, Richard Heathfield wrote:
I answered that question already (see the above link).
>If thats C's way of doing things. I have to admit, it is very messy :( . I
really can't find why it is better than:
> std::vector<std ::stringsvec;
Well, for starters, because it does compile.

you must be using Google Groups, thats why I don't see your post. Anyway,
Richard is right. It won't compile (this is comp.lang.c )
Yes I do. There's better spam filters than just blocking a service...
I'm also right; I meant that the other way is better than the latter
because the former *does* compile. (unlike the latter that does not)
Sep 12 '08 #41
vi******@gmail. com writes:
On Sep 12, 1:18 pm, Richard<rgr...@ gmail.comwrote:

[replying to me]
>Minus 3 for being too late on your attempt to get promoted into the
c.l.c "reg" upper echelon. But that atttempt combined with your
"indeeds", your "Mr heathfields" and various nauseating attempts at
belittling nOObs should ensure at least a cushion at RHs feet in the
near future.

I'm tired of this. I don't give a crap what Heathfield thinks of me.
I'm here to learn C and help others do the same, not to socialize.
Hmmmm. Indeed. It's "Mr Heathfield" to you.
Sep 12 '08 #42
Pilcrow <Pi******@gmail .comwrote:
On Wed, 10 Sep 2008 22:05:46 +0000, Richard Heathfield
Pilcrow said:
Try using fgets(), and strtok(). strtok() will allow you to define word
separators to your taste.
This is poor advice for a beginner. Whilst strtok does have its uses, it
also has issues - traps for the unwary programmer. These derive from its
maintenance of significant state between calls, which makes it unsuitable

I understood that, and I am a 'beginner'. It is very adequately covered
in textbooks (see 'C in a Nutshell', ISBN 0-596-00697-7, page 440),
somewhat less so in K&R2. And I gave the questioner an example to help
him. My dissatisfaction with strtok() is that repeated separation
characters are treated as one, making it difficult to present the user
with an intuitively understandable interface. It is not usually a good
idea to equate ignorance and stupidity.
There is also the catch that strtok() scribbles over its parameter,
meaning that you cannot use it to tokenise either a string literal, or
data you want to keep. This is something that catches out a lot of less
well-informed newbies.

Richard
Sep 12 '08 #43
arnuld <su*****@invali d.addresswrote:
If thats C's way of doing things. I have to admit, it is very messy :( . I
really can't find why it is better than:

std::vector<std ::stringsvec;
Confucius, he says: "if you want C++, you know where to find it".

Richard
Sep 12 '08 #44
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
arnuld <su*****@invali d.addresswrote:
>If thats C's way of doing things. I have to admit, it is very messy :( . I
really can't find why it is better than:

std::vector<std ::stringsvec;

Confucius, he says: "if you want C++, you know where to find it".

Richard
If I were looking at designing solutions in C for such things then it
would be remiss of me NOT to look to see how C++ has done it in the
meantime. It could lead to a lot of time saving. Sure you can not use
the C++ syntax but things are never there for "no reason". And in that
context mentioning the way C++ does it here is clearly topical and
possibly useful to C library designers.
Sep 12 '08 #45
arnuld wrote:
I searched the c.l.c archives provided by Google as Google Groups with
"word input" as the key words and did not come up with anything good.
C++ has std::string for taking a word as input from stdin.

Could you identify the std::string feature that implements this? I
couldn't find any use of the word "word" anywhere in section 21 of the
C++ standard, which describes std::string.
Sep 12 '08 #46
Richard wrote:
Richard Heathfield <rj*@see.sig.in validwrites:
....
>I wish you wouldn't. You have every right to say what you said. I wasn't
being "precious" about it - merely surprised! In fact, I'd be quite
curious to know more about *why* you have a lot of trouble reading my
code. Maybe there's something I can change to make it easier for you to
read without making it more difficult for myself and others.

Speaking for myself and knowingly only picking on style things:

I hate this move to putting braces on their own lines. Its a horrible
waste of vertical space and "3 levels" for one unit is not natural.
Vertical space is not in short supply. Personally, I handle that issue
the same way Richard Heathfield does. My reason is that it makes it
easier to identify and move block statements around when there's a set
of lines which is used for the block, and only that block, including the
delimiting curly brackets.
Also you adopt the non "standard" option of putting your values to
compare against on the left. While "clever" it does read as traditional
"English" and is not adopted widely elsewhere.

e.g

while( 0 == getValue(t))
doSomething(t);
I don't personally use this style, for reasons similar to yours.
However, are you aware of the reason why some people do this? When a
literal is the left operand of a comparison, rather than the right,
there is no danger of your code being silently compiled if you
accidentally type "=" instead of "==". I'll grant you that this doesn't
make any difference when the right operand is also something which could
not be the left operand of an assignment, such as a function call.
However, this kind of rule is much more effective when used
consistently, rather than always asking yourself "is it needed here?". I
tried this style, but found it very hard to break old habits; but I
would not criticize people for adopting it.
Sep 12 '08 #47
James Kuyper <ja*********@ve rizon.netwrites :
Richard wrote:
>Richard Heathfield <rj*@see.sig.in validwrites:
...
>>I wish you wouldn't. You have every right to say what you said. I
wasn't being "precious" about it - merely surprised! In fact, I'd
be quite curious to know more about *why* you have a lot of trouble
reading my code. Maybe there's something I can change to make it
easier for you to read without making it more difficult for myself
and others.

Speaking for myself and knowingly only picking on style things:

I hate this move to putting braces on their own lines. Its a horrible
waste of vertical space and "3 levels" for one unit is not natural.

Vertical space is not in short supply. Personally, I handle that issue
the same way Richard Heathfield does. My reason is that it makes it
easier to identify and move block statements around when there's a set
of lines which is used for the block, and only that block, including
the delimiting curly brackets.
Sounds very rare to me. This moving blocks around. And even so its one
key stroke away to realign etc. hardly worth adopting an entire new
layout to support. I have emacs set up that a single sequence collects
the entire scope into the clipboard anyway.
>
>Also you adopt the non "standard" option of putting your values to
compare against on the left. While "clever" it does read as traditional
"English" and is not adopted widely elsewhere.

e.g

while( 0 == getValue(t))
doSomething(t);

I don't personally use this style, for reasons similar to
yours. However, are you aware of the reason why some people do this?
Yes. Well, one reason. And its not the same as the other one (which I
knew too :-;).
When a literal is the left operand of a comparison, rather than the
right, there is no danger of your code being silently compiled if you
accidentally type "=" instead of "==". I'll grant you that this
Fabricated and blown out of all proportion IMO. What about protecting
against someone typing "a==0" instead of "a=0". or one of a million
other errors. Its a coding error. And 2 seconds testing or debugging
puts that right.
doesn't make any difference when the right operand is also something
which could not be the left operand of an assignment, such as a
function call. However, this kind of rule is much more effective when
used consistently, rather than always asking yourself "is it needed
here?". I tried this style, but found it very hard to break old
habits; but I would not criticize people for adopting it.
I would. The perceived benefits are more than offset by the non standard
"reading" of the code. In my opinion of course. I now expect the usual
sycophants to appear telling us how their productivity increased 30000%
when they adopted this notation ....

It's amusing that the people I know you use this "back to front" trend
are also some of the worst "team players" I have ever encountered and
tend to be jobs worth language lawyers than good, practical programmers
interested in contributing to a consistent and maintainable code base.
Sep 12 '08 #48
vi******@gmail. com said:
On Sep 12, 1:18 pm, Richard<rgr...@ gmail.comwrote:

[replying to me]
>Minus 3 for being too late on your attempt to get promoted into the
c.l.c "reg" upper echelon. But that atttempt combined with your
"indeeds", your "Mr heathfields" and various nauseating attempts at
belittling nOObs should ensure at least a cushion at RHs feet in the
near future.

I'm tired of this.
Yes, it's tiresome. But he's an attention-seeker, like all trolls. If you
never, ever reply to him, maybe - just *may*be - he'll get bored and drift
away, and the average C understanding of the group will increase by a
small but significant amount.
I don't give a crap what Heathfield thinks of me.
Neither should you. The best strategy is to give people every reason to
think highly of you whilst, at the same time, not worrying whether or not
they do.
I'm here to learn C and help others do the same, not to socialize.
Right.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 12 '08 #49
Richard Heathfield <rj*@see.sig.in validwrites:
vi******@gmail. com said:
>On Sep 12, 1:18 pm, Richard<rgr...@ gmail.comwrote:

[replying to me]
>>Minus 3 for being too late on your attempt to get promoted into the
c.l.c "reg" upper echelon. But that atttempt combined with your
"indeeds", your "Mr heathfields" and various nauseating attempts at
belittling nOObs should ensure at least a cushion at RHs feet in the
near future.

I'm tired of this.

Yes, it's tiresome. But he's an attention-seeker, like all trolls. If you
never, ever reply to him, maybe - just *may*be - he'll get bored and drift
away, and the average C understanding of the group will increase by a
small but significant amount.
Not if there is no one to challenge you and your humongous ego and
inflated head.
>
>I don't give a crap what Heathfield thinks of me.

Neither should you. The best strategy is to give people every reason to
think highly of you whilst, at the same time, not worrying whether or not
they do.
Vippstar's contributions to nOObs are invariably poorly worded or wrong
and then followed up with a "yes, I made a mistake there I meant to say
......".

Only a complete fool would not have noticed his attempts to ingratiate
himself with you and your clique by parroting the "Mr heathfield" form
of address and the cringingly horrible use of "Indeed" to promote an
image of knowledge, seniority and peer acceptance.
>
>I'm here to learn C and help others do the same, not to socialize.

Right.
It's a shame that decency and politeness can not be mixed with "learning
and helping" in too many cases here. To be social costs nothing.

So basically, stick it where the sun does not shine you obnoxious
arse
Sep 12 '08 #50

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

Similar topics

11
6088
by: name | last post by:
Here is a first attempt at a line/word wrapping utility. Seems to work okay, but lacks some checking stuff, etc. --------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h>
9
2624
by: Limpor | last post by:
Hi there, I'm very new to C program, I'm about to write a function that read input from standard input, and then returns a pointer to the next word, then i can use it later to print out all the words, but when i run it, i got "Segmentation fault " at the end of output line, this is my code, I've been working on this for a few days, but I still cannot get right, can someone can help me? please! #include <stdio.h> #include <stdlib.h> #include...
27
3172
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I have a fully-portable C program (or at least I think I do). It works fine on Windows, but malfunctions on Linux. I suspect that there's something I don't know about the standard input stream that's causing the problem. Here's how I wrote the program originally: #include <stdio.h> #include <string.h>
3
3186
by: Sevla | last post by:
hello, im having a problem to change a particular word in a line, can´t find where is my mistake also i would like to know how to make this program check automatically if a particular word exists on the line you got to you exchange it or not i didnt find the right condition to do it
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11102
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
10719
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...
1
7953
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
7112
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
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...
1
4597
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
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.