473,386 Members | 1,830 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,386 software developers and data experts.

to get more knowledge in 'c'

hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Sep 24 '06 #1
23 1904
anand devarajan wrote:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge
Ok , write a programme which eliminates the blanks from
the end of every line in its standard input and prints the
result on standard output.

Sep 24 '06 #2
Spiros Bousbouras wrote:
anand devarajan wrote:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Ok , write a programme which eliminates the blanks from
the end of every line in its standard input and prints the
result on standard output.
Oh yeah , to make it more interesting the programme should
use a constant amount of memory regardless of how large
the lines are.

Sep 24 '06 #3
Ico
anand devarajan <is**********@gmail.comwrote:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge
Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.

Sep 24 '06 #4
Spiros Bousbouras wrote:
anand devarajan wrote:
>hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Ok , write a programme which eliminates the blanks from
the end of every line in its standard input and prints the
result on standard output.
Good idea.

There are some idioms in C which you can re-use over and over every time
you see a problem like this.

Here is one that copies each character from standard input to standard
output:

First you define an int variable to hold the result of getchar. That
will be a value from 0 to UCHAR_MAX if successful, and a negative value
called EOF if unsuccessful. Don't try to use a char variable for this.

int ch;

Then you start a loop. Each time through the loop, there is a complex
expression that is evaluated. First, the getchar function is called and
the result is stored in ch. Then the result is compared against the
constant EOF. The loop continues while the value returned is not EOF.

while( (ch = getchar()) != EOF )

{

/* Inside the loop, for each character, you must output it */

putchar(ch);

}

And make sure to remember to end your main function with
return 0;

Here's the complete program:

#include <stdio.h>

int main(void)
{
int ch;
while((ch = getchar()) != EOF)
{
putchar(ch);
}
return 0;
}

Now think about how to modify this basic copying program, to remove any
spaces from the end of lines.

You can test whether you have read a space, a newline character, or some
other type like this:

if(ch == ' ')
{
/* do something */
}
else if(ch == '\n')
{
/* do something else */
}
else
{
/* do something different */
}

There is a tricky part though, as you will be reading the space
characters before the newline comes in. You don't know how many space
characters will come in. You might read 10 of them and then find there
is a non-space character. In that case the 10 spaces you read were not
at the end of the line but in the middle, and they must be preserved in
the output.

I would introduce a new variable, to keep track of how many spaces have
been read. When I read a space, I will just increment the counter, but
not actually output anything. When I read a newline, I will reset the
counter to zero but not output anything except the newline. But when I
read something that is neither a space nor a newline, I must print some
spaces, according to the current value of the counter. I will then reset
the counter and print the actual character that was read.

Can you implement this in C? You will need to add one or two new
variables and another loop inside.

Or perhaps you can think of an even better way to solve the problem?

--
Simon.
Sep 24 '06 #5
anand devarajan posted:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge
How about this:

Write a function with the following signature:

void FindReplace(char *,char const *,char const *)

The first argument is a pointer to a modifiable null-terminated string
which is to be processed and altered. The second argument is a pointer to a
null-terminated string indicating which characters are to be searched for.
The third argument is a pointer to a null-terminated string specifying the
replacement characters. So for instance, if the function were invoked as
follows:

char str[] = "The man walked into the bar."

FindReplace(str,"aeiou","vwxyz");

, then "str" will be changed to: "Thw mvn wvlkwd xnty thw bvr."

--

Frederick Gotham
Sep 24 '06 #6
Ico wrote:
anand devarajan <is**********@gmail.comwrote:
>hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.
And add a spell checker. 'interpunction'?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Sep 24 '06 #7
Spiros Bousbouras wrote:
Spiros Bousbouras wrote:
>anand devarajan wrote:
>>i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Ok , write a programme which eliminates the blanks from
the end of every line in its standard input and prints the
result on standard output.

Oh yeah , to make it more interesting the programme should
use a constant amount of memory regardless of how large
the lines are.
And just to make it more elegant, handle embedded tabs, assuming
tabstops every 8th position.

If anand doesn't learn to stop top-posting he will stop getting any
help here.

--
Some informative links:
<news:news.announce.newusers
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>

Sep 25 '06 #8
In article <35******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
>Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.
>And add a spell checker. 'interpunction'?
"Interpunction" is a perfectly cromulent word.

-- Richard
Sep 25 '06 #9
Joe Wright wrote:
Ico wrote:
>anand devarajan <is**********@gmail.comwrote:
>>>
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper
capitalization and interpunction to a usenet message.

And add a spell checker. 'interpunction'?
No problem. Interpunction refers to the act of transferring
punctures between pneumatic tires. :-) This is different from
'extreme interpunction', which has to do with the final rites for
interpreters.

--
Some informative links:
<news:news.announce.newusers
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
Sep 25 '06 #10
Joe Wright said:
Ico wrote:
>anand devarajan <is**********@gmail.comwrote:
>>hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.
And add a spell checker. 'interpunction'?
You need to get a new glarkurettor for your vocabulator. :-)

--
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)
Sep 25 '06 #11
>>Here is one for you: write a program that adds proper capitalization and
>>interpunction to a usenet message.
>In article <35******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
>>And add a spell checker. 'interpunction'?
Chuck Falconer wrote (in a message whose ID I failed to capture):
>Interpunction refers to the act of transferring
punctures between pneumatic tires. :-)
In article <ef**********@pc-news.cogsci.ed.ac.uk>
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>"Interpunction" is a perfectly cromulent word.
"Cromulent" is not (yet?) an accepted word in most dictionaries
(see <http://www.urbandictionary.com/define.php?term=Cromulent>),
but "interpunction" today might be the act of inserting the
interpunct, a sort of center decimal point ("&middot;" in HTML-ese),
that was used in Latin. See <http://en.wikipedia.org/wiki/Interpunct>.
This word-separating character was apparently originally called an
"interpunction", so it is now actually valid as both a noun and a verb.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Sep 25 '06 #12
Ico
Joe Wright <jo********@comcast.netwrote:
Ico wrote:
>anand devarajan <is**********@gmail.comwrote:
>>hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.
And add a spell checker. 'interpunction'?
I must admit I usually don't use spellcheckers, but I believe 'interpunction'
is a perfectly valid word ?

$ dict interpunction

1 definition found

From The Collaborative International Dictionary of English v.0.48 [gcide]:

Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
interpungere, interppunctum, to interpoint. See {Inter-}, and
{Point}.]
The insertion of points between words or sentences;
[1913 Webster]

--
:wq
^X^Cy^K^X^C^C^C^C
Sep 25 '06 #13
Ico schrieb:
Joe Wright <jo********@comcast.netwrote:
>>Ico wrote:
>>>anand devarajan <is**********@gmail.comwrote:

hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.

And add a spell checker. 'interpunction'?

I must admit I usually don't use spellcheckers, but I believe 'interpunction'
is a perfectly valid word ?

$ dict interpunction

1 definition found

From The Collaborative International Dictionary of English v.0.48 [gcide]:

Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
interpungere, interppunctum, to interpoint. See {Inter-}, and
{Point}.]
The insertion of points between words or sentences;
[1913 Webster]
FWIW:
interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
Maybe this is a similar case of "false friends" for you.

-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 25 '06 #14
Ico
Michael Mair <Mi**********@invalid.invalidwrote:
Ico schrieb:
>Joe Wright <jo********@comcast.netwrote:
>>>Ico wrote:
anand devarajan <is**********@gmail.comwrote:

>hi friends,
i need some one to frame me questions for to write programs,it
>might be simple ones like prime no. prg but i need this type of
>coaching for to develop my programming knowledge

Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.

And add a spell checker. 'interpunction'?

I must admit I usually don't use spellcheckers, but I believe 'interpunction'
is a perfectly valid word ?

$ dict interpunction

1 definition found

From The Collaborative International Dictionary of English v.0.48 [gcide]:

Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
interpungere, interppunctum, to interpoint. See {Inter-}, and
{Point}.]
The insertion of points between words or sentences;
[1913 Webster]

FWIW:
interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
Maybe this is a similar case of "false friends" for you.
Yes, you're right. Germany is only next door here, so that's where my
mixup came from. Punctuation it is :)
--
:wq
^X^Cy^K^X^C^C^C^C
Sep 25 '06 #15
CBFalconer wrote:
>
If anand doesn't learn to stop top-posting he will stop getting any
help here.
While it's true that anand top-posted in his only message
to this thread (the only one my news server sees, anyhow), I
feel that he should be forgiven. It is, after all, no easy
matter to avoid top-posting in a thread's first message.

--
Eric Sosman
es*****@acm-dot-org.invalid
Sep 25 '06 #16
Ico wrote:
$ dict interpunction

1 definition found

From The Collaborative International Dictionary of English v.0.48 [gcide]:

Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
interpungere, interppunctum, to interpoint. See {Inter-}, and
{Point}.]
The insertion of points between words or sentences;
[1913 Webster]
It's in a 1996 Webster's as well. I like the word, because I've been
frustrated before trying to describe it when doing various forms of text
processing ;-)
Sep 25 '06 #17
Chris Torek wrote:
>>>Here is one for you: write a program that adds proper capitalization and
interpunction to a usenet message.
>In article <35******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
>>And add a spell checker. 'interpunction'?

Chuck Falconer wrote (in a message whose ID I failed to capture):
>Interpunction refers to the act of transferring
punctures between pneumatic tires. :-)

In article <ef**********@pc-news.cogsci.ed.ac.uk>
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>"Interpunction" is a perfectly cromulent word.

"Cromulent" is not (yet?) an accepted word in most dictionaries
but "interpunction" today might be the act of inserting the
interpunct, a sort of center decimal point ("&middot;" in HTML-ese),
that was used in Latin. See <http://en.wikipedia.org/wiki/Interpunct>.
This word-separating character was apparently originally called an
"interpunction", so it is now actually valid as both a noun and a verb.
The word "interpunction" long predates HTML.

The word "cromulent" is a humorous neologism from a popular animated TV
show.
Sep 25 '06 #18
Op 25 Sep 2006 10:09:34 GMT schreef Ico:
Michael Mair <Mi**********@invalid.invalidwrote:
>Ico schrieb:
>>Joe Wright <jo********@comcast.netwrote:
Ico wrote:
>anand devarajan <is**********@gmail.comwrote:
>
>>hi friends,
> i need some one to frame me questions for to write programs,it
>>might be simple ones like prime no. prg but i need this type of
>>coaching for to develop my programming knowledge
>
>Here is one for you: write a program that adds proper capitalization and
>interpunction to a usenet message.

And add a spell checker. 'interpunction'?

I must admit I usually don't use spellcheckers, but I believe 'interpunction'
is a perfectly valid word ?

$ dict interpunction

1 definition found

From The Collaborative International Dictionary of English v.0.48 [gcide]:

Interpunction \In`ter*punc"tion\, n. [L. interpunctio, fr.
interpungere, interppunctum, to interpoint. See {Inter-}, and
{Point}.]
The insertion of points between words or sentences;
[1913 Webster]

FWIW:
interpunction(Engl.) != Interpunktion(German) == punctuation(Engl.)
Maybe this is a similar case of "false friends" for you.

Yes, you're right. Germany is only next door here, so that's where my
mixup came from. Punctuation it is :)
But in Dutch it's interpunctie again :)
No word like punctuatie.
--
Coos
Sep 25 '06 #19
I agree! ;-)

"Eric Sosman" <es*****@acm-dot-org.invalidwrote in message
news:_-******************************@comcast.com...
CBFalconer wrote:

If anand doesn't learn to stop top-posting he will stop getting any
help here.

While it's true that anand top-posted in his only message
to this thread (the only one my news server sees, anyhow), I
feel that he should be forgiven. It is, after all, no easy
matter to avoid top-posting in a thread's first message.

Oct 2 '06 #20
anand devarajan wrote:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg but i need this type of
coaching for to develop my programming knowledge
You're asking others how to challenge yourself? I don't think you're going to
get far in life on that mantra.
Oct 2 '06 #21
anand devarajan wrote:
hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg

Simple? Like prime no. prg? !?!?

Ok. Find the first 45 prime numbers n, such that 2^n-1 is also prime.
.... ;-)

Oct 2 '06 #22
jmcgill said:
anand devarajan wrote:
>hi friends,
i need some one to frame me questions for to write programs,it
might be simple ones like prime no. prg


Simple? Like prime no. prg? !?!?

Ok. Find the first 45 prime numbers n, such that 2^n-1 is also prime.
... ;-)
2 is the only such number.

Proof that it is such a number: 2 - 1 is 1, and 2 ^ 1 is 3.

Proof that it is the only such number: Let n be any positive integer greater
than 2. Either n is even (in which case it is not prime), or n - 1 is even
and therefore either 2 or not prime (and xoring it with 2 will not change
its parity, but will zero it if it is 2, and 0 is not prime).

--
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)
Oct 2 '06 #23
Richard Heathfield wrote:
2 is the only such number.

Proof that it is such a number:
Ahhhh, great answer!

I meant, as shirley you realize, (2 raised to the power of n), minus 1.

I appreciate being called out on my lack of precision (really).

Oct 2 '06 #24

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
0
by: MarionEll | last post by:
Premier XML Industry Event Slated for Dec. 7-12 in Philadelphia; Presenters Include Adobe, BEA, Microsoft, IBM, Sun, Hewlett-Packard, Oracle Alexandria, Va. Sept. 30, 2003 - IDEAlliance, a...
0
by: MarionEll | last post by:
Premier XML Industry Event Slated for Dec. 7-12 in Philadelphia; Presenters Include Adobe, BEA, Microsoft, IBM, Sun, Hewlett-Packard, Oracle Alexandria, Va. Sept. 30, 2003 - IDEAlliance, a...
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
86
by: CJ Taylor | last post by:
How does one become an MVP?
13
by: David | last post by:
Hi all, I have a singleton ienumerable that collects data from a database. I have listed the code below. It has the usual methods of current, move and reset. I need to go to a certain position...
2
by: nano2k | last post by:
Hi It's maybe offtopic, but do you guys have an ideea of how to develop an knowledge base for troubleshooting an application? Picture this. After deploying an application to multiple locations,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.