473,698 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP!! Two questions from <<the c programming language>>

Tak
Exercise 1-9. Write a program to copy its input to its output,
replacing each string of one or
more blanks by a single blank.

Exercise 1-10. Write a program to copy its input to its output,
replacing each tab by \t, each
backspace by \b, and each backslash by \\. This makes tabs and
backspaces visible in an
unambiguous way.

Who could sent me the codes, Thanks very much! My email:
ka******@gmail. com

May 31 '07 #1
27 2005
Tak wrote:
Exercise 1-9. Write a program to copy its input to its output,
replacing each string of one or
more blanks by a single blank.

Exercise 1-10. Write a program to copy its input to its output,
replacing each tab by \t, each
backspace by \b, and each backslash by \\. This makes tabs and
backspaces visible in an
unambiguous way.

Who could sent me the codes, Thanks very much! My email:
ka******@gmail. com
No, that's not how it works here. You post your attempt, we help you
with problems. We don't do homework.

--
Ian Collins.
May 31 '07 #2
Tak wrote:
Exercise 1-9. Write a program to copy its input to its output,
replacing each string of one or
more blanks by a single blank.

Exercise 1-10. Write a program to copy its input to its output,
replacing each tab by \t, each
backspace by \b, and each backslash by \\. This makes tabs and
backspaces visible in an
unambiguous way.

Who could sent me the codes, Thanks very much! My email:
ka******@gmail. com
The /point/ about doing the exercises is to /learn by doing/. If
you don't do the work, the learning doesn't happen, or doesn't
happen as well.

Do the work. We can crit the result, but you have to show willing.

--
JUC 2007, submit: http://hpl.hp.com/conferences/juc2007/submission.html

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

May 31 '07 #3
Tak
No, that's not how it works here. You post your attempt, we help you
with problems. We don't do homework.

--
Ian Collins.


No, I think you are misunderstandin g.
It's not homework;

I can't work out Exercise 1-9.
My code of Exercise 1-10 is like this:

#include <stdio.h>

main()
{
char c;

while ((c = getchar()) != EOF)
{
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
putchar(c);
}
}
I don't know whether it's right or not?

May 31 '07 #4
Tak wrote:
>No, that's not how it works here. You post your attempt, we help you
with problems. We don't do homework.

--
Ian Collins.

No, I think you are misunderstandin g.
It's not homework;

I can't work out Exercise 1-9.
You have the basic structure, so you should be able to change your loop
to spot and filter spaces.
My code of Exercise 1-10 is like this:

#include <stdio.h>

main()
main returns int, if you compiler didn't warn you, turn up the warnings
until it does.
{
char c;

while ((c = getchar()) != EOF)
{
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
putchar(c);
}
}
I don't know whether it's right or not?
It looks OK, but have you tried it? It should be easy enough to test.

--
Ian Collins.
May 31 '07 #5
Tak
I know how to do, Thank you!

May 31 '07 #6
Tak wrote:
I know how to do, Thank you!
Good. Next time, please keep some context from the message you are
replying to.

--
Ian Collins.
May 31 '07 #7
Ian Collins <ia******@hotma il.comwrites:
Tak wrote:
[...]
>{
char c;

while ((c = getchar()) != EOF)
[snip]
>I don't know whether it's right or not?
It looks OK, but have you tried it? It should be easy enough to test.
What type does getchar() return?

See also section 12 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keit h) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 31 '07 #8
On May 31, 1:55 pm, Tak <kakat...@gmail .comwrote:
No, that's not how it works here. You post your attempt, we help you
with problems. We don't do homework.
--
Ian Collins.

No, I think you are misunderstandin g.
It's not homework;

I can't work out Exercise 1-9.
My code of Exercise 1-10 is like this:

#include <stdio.h>

main()
{
char c;

while ((c = getchar()) != EOF)
{
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
putchar(c);
}

}

I don't know whether it's right or not?
everything is ok...why don't you run this and see?

why you can't work out 1-9 ?? I can give you idea, you implement it.

accept the char.. if it is a space set a flag saying you got one
space. you should ignore further spaces if this flag is set, otherwise
display further chars.
Continue this till eof.

Huuuh...didn't get idea???? Follow the step

Algorithm trim_space

while EOF
do
begin
input char
if char = space then
begin
if flag = 0 then
begin
let flag = 1;
print char;
end
end
else
begin
let flag = 0
print char
end
end
goto step 2
end while

Bye
Guru Jois

May 31 '07 #9
Tak wrote:
>No, that's not how it works here. You post your attempt, we help you
with problems. We don't do homework.
(fx:hint (fx:snipped-signature))
No, I think you are misunderstandin g.
It's not homework;

I can't work out Exercise 1-9.
My code of Exercise 1-10 is like this:

#include <stdio.h>

main()
{
char c;
/int/ c.
while ((c = getchar()) != EOF)
`getchar` returns an `int`, because it must be able to return
every character value /and one more/, viz EOF. (Yes, this
presents problems on systems where `sizeof(int) == sizeof(char)`.)
I don't know whether it's right or not?
Does it pass your test cases?

--
"You've spotted a flaw in my thinking, Trev" Big Al,/The Beiderbeck Connection/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

May 31 '07 #10

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

Similar topics

13
1586
by: yy0127 | last post by:
I don't know why i entered the below code and it will miss some records. Anyone can help me??? users = {} users1 = {} while 1: user, serviceType, msgType, inOut, date, time, numBytes =
6
1185
by: stephane | last post by:
I am preparing an exam and I have a copy of last year exam. I answered the first questions and I wander if I am right or wrong. Can someone have a look at the questions and at my answers please? There is no code to write just general questions about the two class'. the code: /--
8
1174
by: t3hseen | last post by:
what the values of the following expressions: if illegal or unpredictable please state so. stat char *arrax ="C is my favourite"; stat char *lp=arrax; static int five=5; a)*(arrax + 8) b)*arrax+2 c)lp
0
2067
by: Henry | last post by:
Using ideas provided by some of you I was able to figure out how to get the names of the parameters fields of a crystal report specified at run time. The code below just basically puts the data into a comboBox. One thing I noticed, however, is that this method shows me both the parameters used by the main report and parameters used by the sub-report(s).
2
2762
by: KhzQas | last post by:
Hello mates. I am taking my very first programming language (C Programming) and as for practice purposes, I surf sites and try out to make programs. I am having problems with the following C Programming problem. 1) You are required to use at least one for() loop to control the printing of a table in this lab. 2) Do not use the scanf() function in this lab, use the getchar() instead. 3) Your table will consist of three data type...
20
2201
by: Mike | last post by:
Hi all, I am cramming for an technical interview about C++ and programming... I believe there will be problems on data-structures and algorithms... could anybody recommend some online resources/references/websites so that I can find summary sheet about the confusing points of C++ and typical storage/time complexity of common data structures and common algorithms? I do have those big textbooks but I found they don't provide a fast...
3
1734
by: Dr. Erhard Moenige | last post by:
Hi all C-Programmers everywhere ! I 've been learning programming c in console-applications for 1 year and now I'm tired of seeing this boring console-application in my programms. Because of that I decited to programme c in Windows in the CVI Development by National Instruments. I've bought this nice development,but when I'd installed it I found out that is more complex than I had expected. That is why I asked you please to help me...
2
1129
by: nachu | last post by:
I Would Like To Know How Can The Skilll In C Be Improved So As It Would Help For "c Programming Contests"(b'coz I Am In One, So...)
3
1183
by: fdu.xiaojf | last post by:
Hi all, I'm not skilled at programming, so sorry for my ignorance. My questions: (1) which is the better way to calculate the value of attributes of a class ? for example: (A) def cal_attr(self, args): #do some calculations
2
1456
by: yourchandrashekhar | last post by:
I've good programming experience in C++ and now i want to start programming a small UNIX OS kernel. I request in common to anyone over the net to come forward and give me the initial insight of how to get started.... Anyone who finds it interesting could please get to me at one of the follwowing email ID's: your_shekhar@hotmail.com
0
9156
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
9021
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...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
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
6518
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
5860
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
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.