Writing a specific program

A

Albert

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

Madhav

Albert said:
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.
 
M

moosdau

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

Chuck F.

Albert said:
>
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/>
 
N

Niklas Norrthon

Albert said:
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
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Albert said:
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' ?
 
K

Kenny McCormack

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.
 
M

Malcolm

Albert said:
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).
 
A

Albert

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
 
R

Richard Heathfield

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.
 
R

Richard Heathfield

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?
 
K

Keith Thompson

Albert said:
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.
 
R

Richard Heathfield

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.
 
M

Mark McIntyre

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
 
J

Jordan Abel

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.
 
R

Randy Howard

Keith Thompson wrote
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.
 
R

Randy Howard

Mark McIntyre wrote
(in article said:
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.
 
M

Mark McIntyre

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
 
M

Mark McIntyre

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top