By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

Writing a specific program

P: n/a
how do i write a program that outputs its input if its input is more
than 80 characters?

Dec 29 '05 #1
Share this Question
Share on Google+
26 Replies


P: n/a
Albert wrote:
how do i write a program that outputs its input if its input is more
than 80 characters?


This sounds like homework. Please DO NOT expect someone to do your
homework. If you want any help, show us what you have done.

Madhav.

Dec 29 '05 #2

P: n/a
use a loop to get input,
put the values into a buffer or a file,
when the input is over,
output the result.

Dec 29 '05 #3

P: n/a
Albert wrote:

how do i write a program that outputs its input if its input is
more than 80 characters?


Read the input into a buffer. If it is over 80 chars long output
it, otherwise discard it.

If you can't express your needs accurately and unambiguously you
will have great difficulty in programming accurately.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Dec 29 '05 #4

P: n/a
Albert wrote:
how do i write a program that outputs its input if its input is more
than 80 characters?

What should it do if it's less than 80 characters ?

And what's 'input' ? Do you mean the entire input,
or are you dealing with line based text input, so you
mean 'what if a line is more than 80 characters' ?
Dec 29 '05 #5

P: n/a
"Albert" <al*****************@gmail.com> writes:
how do i write a program that outputs its input if its input is more
than 80 characters?


#include <stdio.h>
#include <string.h>

int main(void)
{
char buf[100];
size_t sz;

sz = fread(buf, 1, sizeof buf, stdin);
if (sz > 80) {
do {
size_t r;
r = fwrite(buf, 1, sz, stdout);
if (r < sz) {
/* do error handling here */
}
sz = fread(buf, 1, sizeof buf, stdin);
} while (sz > 0);
}
return 0;
}

/Niklas Norrthon
Dec 29 '05 #6

P: n/a
In article <11*********************@g49g2000cwa.googlegroups. com>,
Albert <al*****************@gmail.com> wrote:
how do i write a program that outputs its input if its input is more
than 80 characters?


length > 80

Yup, that's the whole program. Up to you to provide the necessary shell
wrappings, input and output files, etc.

Dec 29 '05 #7

P: n/a

"Albert" <al*****************@gmail.com> wrote

how do i write a program that outputs its input if its input is more
than 80 characters?

Firstly you need a proper specification from your user.
Does he want the input from stdin, or from a file?
Does he mean "pass any lines longer than 80 characters" to stdout, or does
he want any file longer than 80 characters to be output (and where to).

Secondly, are there any restrictions on unusual inputs? For instance if a
line is 10GB, does the program have to pass it out? Can we assume files or
even lines will fit in memory? If the program runs out of memory, what is it
meant to do? Can it truncate long input? What if input contains non-ASCII
characters (including NULs)?

Once you've got answers to the above questions, you have your system
requirements, and you cna start coding, but most software engineers would
say not before (at least for beginners).
Dec 29 '05 #8

P: n/a
You're complete utter bullshit.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such shit

Dec 30 '05 #9

P: n/a
Albert said:
You're complete utter [expletive deleted].
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such
[expletive deleted]


You know something? I almost felt sorry for you. I almost gave you a long
reply explaining how to set about tackling a problem like this. Almost.

And then I looked again at your choice of words, and I thought about what
contempt you have for the readers of this newsgroup, that you are prepared
to throw expletives in their collective face, and I decided not to bother
after all.

When you're all growed up, ask again.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 30 '05 #10

P: n/a
y do u care?

Dec 30 '05 #11

P: n/a
Albert said:
y do u care?


If you are asking why I care enough about you to wish to help you learn how
to deal in an adult way with this newsgroup instead of resorting to
childish abuse, the answer is simple: I think you're bright enough to act
like a grown-up, if only the necessity for so doing is once pointed out to
you. Will you prove me wrong?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 30 '05 #12

P: n/a
"Albert" <al*****************@gmail.com> writes:
You're complete utter bu**sh**.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such sh**


[quotation edited for offensive language]

Here's some friendly advice.

First, read <http://cfaj.freeshell.org/google/> and follow its advice.

Second, if you're going to ask for help with a problem, you need to
define unambiguously what the problem is. Your original question was:

how do i write a program that outputs its input if its input is more
than 80 characters?

This is extraordinarily ambiguous. With a little effort, I could
probably think of at least half a dozen mutually inconsistent
interpretations for this -- and I suspect none of them would match
what you actually meant. Do you mean more than 80 character per line
or more than 80 characters total? What should the program do if the
input isn't more than 80 characters? And so on. Rather than wasting
our time trying to guess what you really meant, several people asked
you to clarify your question -- and you never bothered to do so.

Are you saying this is an exercise in K&R? I don't recall seeing it.
If it's there, I'm reasonably certain K&R worded it much more
precisely. Can you provide an exercise number? Is it from the first
edition or the second?

Your question looks very much like a homework assignment. I don't
know whether it is or not. A lot of people post their homework
questions here and expect us to do their work for them; we are
understandably reluctant to do so. After all, the point of homework
is for the student to learn something by doing the work himself.

If we knew what you were looking for, we could almost certainly write
a C program that meets your requirements -- but then we wouldn't need
you, would we?

The best way for you to learn is to try to write the code yourself.
If you're having problems with it, we can help you. If you can't do
that, perhaps programming is not for you. We're not going to
spoon-feed you the solution.

If you're going to insult people who you're asking for help, you're
not going to get much help. Because of your whining, you're almost
certainly already in a number of killfiles; one stupid little tirade
can be enough to permanently damage your ability to get help here. I
see that some of the regulars are replying to you in other threads, so
maybe you haven't *quite* shot yourself in the foot. But I, for one,
will certainly be less inclined to help you in the future unless you
change your behavior.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 30 '05 #13

P: n/a
Keith Thompson said:
Because of your whining, you're almost certainly already in a number of
killfiles;
He's not in mine - yet. But...
one
....more...
stupid little tirade


will be one too many. And an apology wouldn't go amiss, for his abusive
behaviour earlier on in this thread.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 30 '05 #14

P: n/a
On 29 Dec 2005 18:35:11 -0800, in comp.lang.c , "Albert"
<al*****************@gmail.com> wrote:
You're complete utter bullshit.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such shit


You write messages like this, and expect people to help you?

Imagine you walked up to a stranger and said "can you tell me the way
to the station?" and when asked if you had a map, you replied "f*ck
you, you're complete b****, I've never heard of such sh**". What
would happen next?
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 30 '05 #15

P: n/a
On 2005-12-30, Albert <al*****************@gmail.com> wrote:
You're complete utter bullshit.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such shit


That doesn't mean it can't be homework. My CS240 class assigned
exercises from K&R as homework on occasion - which was the logical thing
to do, as K&R was our textbook.
Dec 30 '05 #16

P: n/a
Keith Thompson wrote
(in article <ln************@nuthaus.mib.org>):
"Albert" <al*****************@gmail.com> writes:
You're complete utter bu**sh**.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such sh**
Second, if you're going to ask for help with a problem, you need to
define unambiguously what the problem is. Your original question was:

how do i write a program that outputs its input if its input is more
than 80 characters?

This is extraordinarily ambiguous. With a little effort, I could
probably think of at least half a dozen mutually inconsistent
interpretations for this -- and I suspect none of them would match
what you actually meant.
When I read it the first time, I thought he was talking about a
quine of some minimum length. Upon -rereading, I came to the
same conclusion you did, and ignored it basically until all the
firestorm erupted after his responses were so inappropriate.
Your question looks very much like a homework assignment. I don't
know whether it is or not. A lot of people post their homework
questions here and expect us to do their work for them; we are
understandably reluctant to do so. After all, the point of homework
is for the student to learn something by doing the work himself.
That is almost true. There are always one or two folks that
will answer anyway, even when it is obviously a homework
problem. Those people make it difficult for this argument to
hold water, unfortunately.
If we knew what you were looking for, we could almost certainly write
a C program that meets your requirements -- but then we wouldn't need
you, would we?
It's he that needs the group, not the other way around. Perhaps
you were being subtle? :-)
If you're going to insult people who you're asking for help, you're
not going to get much help. Because of your whining, you're almost
certainly already in a number of killfiles; one stupid little tirade
can be enough to permanently damage your ability to get help here.


Sadly, sockpuppets are the preferred method of getting around
that little problem. He'll be back, but with another fake
name/account later. People will be helpful until he repeats his
mistake.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 30 '05 #17

P: n/a
Mark McIntyre wrote
(in article <1k********************************@4ax.com>):
On 29 Dec 2005 18:35:11 -0800, in comp.lang.c , "Albert"
<al*****************@gmail.com> wrote:
You're complete utter bullshit.
Have you ever bothered reading The C Programming Language by K&R
before? There's an exercise on this and I simply don't know how to do
it and you expect me to write what I've tried - never heard of such shit


You write messages like this, and expect people to help you?

Imagine you walked up to a stranger and said "can you tell me the way
to the station?" and when asked if you had a map, you replied "f*ck
you, you're complete b****, I've never heard of such sh**". What
would happen next?


In some more civilized parts of the world, he'd get shot
immediately, thereby removing him from the gene pool before the
problem spreads further. In other, less civilized parts of the
world, he would be given a check by the government on a regular
basis, in which to by products to help him in his quest to
become even more antisocial, thereby insuring the increased need
for government oversight in the future.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 30 '05 #18

P: n/a
On Fri, 30 Dec 2005 19:57:56 GMT, in comp.lang.c , Randy Howard
<ra*********@FOOverizonBAR.net> wrote:
Sadly, sockpuppets are the preferred method of getting around
that little problem. He'll be back, but with another fake
name/account later.


The good thing is that ISPs are increasingly including morphing in the
list of unacceptable behaviours documented in their AUPs.
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 30 '05 #19

P: n/a
On Fri, 30 Dec 2005 20:00:03 GMT, in comp.lang.c , Randy Howard
<ra*********@FOOverizonBAR.net> wrote:
In some more civilized parts of the world, he'd get shot
immediately, thereby removing him from the gene pool before the
problem spreads further.


And in the /most/ civilised places, he'd be given a 'Gorbals Kiss' and
a pass to an orthodontist of his choice. :-)

Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 30 '05 #20

P: n/a
Mark McIntyre <ma**********@spamcop.net> wrote:
On Fri, 30 Dec 2005 20:00:03 GMT, in comp.lang.c , Randy Howard
<ra*********@FOOverizonBAR.net> wrote:
In some more civilized parts of the world, he'd get shot
immediately, thereby removing him from the gene pool before the
problem spreads further.


And in the /most/ civilised places, he'd be given a 'Gorbals Kiss' and
a pass to an orthodontist of his choice. :-)


YM Glasgae kiss, don't you?

Richard
Jan 2 '06 #21

P: n/a
Albert a écrit :
You're complete utter bullshit.


Welcome to plonkland.

--
A+

Emmanuel Delahaye
Jan 2 '06 #22

P: n/a
Richard Bos a écrit :
YM Glasgae kiss, don't you?


A Scottish form of 'Glasgow' ?

--
A+

Emmanuel Delahaye
Jan 2 '06 #23

P: n/a
Albert wrote:

Have you ever bothered reading The C Programming Language by K&R
before?
Yes I have.
There's an exercise on this


Which one?

--
pete
Jan 4 '06 #24

P: n/a
pete said:
Albert wrote:

Have you ever bothered reading The C Programming Language by K&R
before?


Yes I have.
There's an exercise on this


Which one?


pete - I can confirm that there is such an exercise. I won't give the number
here unless you ask me to, in case you are using a maeutic approach.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jan 4 '06 #25

P: n/a

Albert schrieb:
how do i write a program that outputs its input if its input is more
than 80 characters?


I don't know how you do that. I for my part most often use the keyboard
to write programs.

Jan 4 '06 #26

P: n/a
On Mon, 02 Jan 2006 23:01:27 +0100, in comp.lang.c , Emmanuel Delahaye
<em***@YOURBRAnoos.fr> wrote:
Richard Bos a écrit :
YM Glasgae kiss, don't you?


A Scottish form of 'Glasgow' ?


Aye Jimmy.

Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 7 '06 #27

This discussion thread is closed

Replies have been disabled for this discussion.