473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Writing a specific program

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

Dec 29 '05 #1
26 1524
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
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
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
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
"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
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

"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
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
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
y do u care?

Dec 30 '05 #11
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
"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
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
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
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
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
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
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
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
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
Albert a écrit :
You're complete utter bullshit.


Welcome to plonkland.

--
A+

Emmanuel Delahaye
Jan 2 '06 #22
Richard Bos a écrit :
YM Glasgae kiss, don't you?


A Scottish form of 'Glasgow' ?

--
A+

Emmanuel Delahaye
Jan 2 '06 #23
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Bart Nessux | last post by:
I understand that most people write functions to reuse code, no? So, I assume it would be better to write functions that are very specific, as opposed to those that are more generic. However, I...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
10
by: cj | last post by:
I'm having a problem writing an insert command to work with a datatable. I've looked at what the sqldataadapter creates and created my insert command to look the same. I have:...
0
by: georges the man | last post by:
The purpose: • Sorting and Searching • Numerical Analysis Design Specification You are to write a program called “StockAnalyser”. Your program will read a text file that contains historical...
12
by: benjamin.krulewitch | last post by:
I'm debugging an issue with a C program that causes the computer to crash, and I'm attempting to log information immediately before the crash occurs. I us my BKprintLog function (see below) to...
3
by: nexus024 | last post by:
I am trying to write a program that will continuously sniff eth0 for a specific UDP packet thats being sent to a specific destination IP, alter the data of the packet, and finally transmit it to the...
6
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
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 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.