473,811 Members | 4,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1565
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.c om, 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************ *********@g49g2 000cwa.googlegr oups.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

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

Similar topics

17
1513
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 have difficulty doing this. My code doesn't need to be super-modular (I don't need functions that can be used in dozens of different programs). So, my functions don't tend to be portbale and can sometimes span one, or perhaps two pages. Is this...
5
45742
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 *air_address;
6
3506
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 written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to customer_record SETUP PROGRAM
4
2181
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
10
3276
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: MySqlAdapter.InsertCommand = New SqlCommand("INSERT INTO billing( type, dsc ) VALUES ( @type, @dsc)", MySqlConnection) But it gives me the following error when MySqlAdapter.Update(MyDt) executes: Must declare the variable '@type' Could someone tell me what I'm...
0
2429
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 price of a stock. The program will allow users to query the stock price of a particular date and output its statistics (mean price, median price and standard deviation) for any specified period. Your program must be menu driven and works as follows.
12
5604
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 write information into a log file. The problem is, i'm not confident that information i write to the log gets saved onto the hard drive before the crash occurs. My understanding of hard drives and OS are that because hard drives are so slow,...
3
3659
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 destination. My script compiles fine and runs fine until it finds the specific packet and tries to alter the payload of the data. Hopefully someone can give me some insight on why it might be doing this... #!/usr/bin/perl -w # # Custom script:...
6
1263
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? """ ----------------------------------------------------------------------------- Name: _writePythonCode.py Purpose: This script writes Python code and thentransfers control to it. Author: MCSEJUNG
0
9607
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
10656
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...
1
10413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9214
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
7674
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
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4353
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
3879
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3027
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.