Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Counting blanks

Reply
Thread Tools

Counting blanks

 
 
CBFalconer
Guest
Posts: n/a
 
      12-01-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>

.... snip ...
>
> hey thanks ur sorce code.i also think that is correct.then u know
> about linklist,i want ur help.bcoz i want to know about how to sort
> the link list using c language.can u help me?


ur was a city in ancient times. I (capitalized) is the first
person pronoun. u has not posted here for several years. bcoz is
totally unrecognizable. Periods are normally followed by at least
one blank. First characters in sentences are usually upper case.
Other (possibly typos) errors are: "linklist" != "link list";
"sorce" probably means "source".

Most of this is not a language problem, but pure carelessness. The
result is, to all practical purposes, unintelligible. Please fix
your message before posting.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
James Fang
Guest
Posts: n/a
 
      12-02-2007
On Dec 1, 5:54 am, (E-Mail Removed) wrote:
> Hi I am new to this forum.
>
> I have taken a class in C some time ago but now I am reading Kernigan
> and Richie's book to refresh my knowledge. I think I have forgotten
> alot and there are no solutions to the exercises. Maybe some people
> here can check through some of my solutions.
>
> Below is a solution to the exercise 1.8.
>
> /* blank counter */
>
> int x, y, z;
>
> void main()
> {
> char c;
>
> fflush(stdin); // start reading from stdin
> while(! feof(stdin) ) {
> switch(c = getchar()) {
> case ' ' : x++; break;
> case '\t': y++; break;
> case '\n': z++;
> }
> }
> fclose(stdin); // clean up
>
> printf("[spaces, tabs, newlines] = [%d, %d, %d]\n", x, y, z);
>
> }


I have a question:

If you use the keyboard as the stdin source, how can the situation :
((c = getchar()) == EOF) met?

My perception is that you have to redirect your stdin to a file and
then run this program.

Thanks!
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-02-2007
James Fang wrote:

> On Dec 1, 5:54 am, (E-Mail Removed) wrote:
>> Hi I am new to this forum.
>>
>> I have taken a class in C some time ago but now I am reading Kernigan
>> and Richie's book to refresh my knowledge. I think I have forgotten
>> alot and there are no solutions to the exercises. Maybe some people
>> here can check through some of my solutions.
>>
>> Below is a solution to the exercise 1.8.
>>
>> /* blank counter */
>>
>> int x, y, z;
>>
>> void main()
>> {
>> char c;
>>
>> fflush(stdin); // start reading from stdin
>> while(! feof(stdin) ) {
>> switch(c = getchar()) {
>> case ' ' : x++; break;
>> case '\t': y++; break;
>> case '\n': z++;
>> }
>> }
>> fclose(stdin); // clean up
>>
>> printf("[spaces, tabs, newlines] = [%d, %d, %d]\n", x, y, z);
>>
>> }

>
> I have a question:
>
> If you use the keyboard as the stdin source, how can the situation :
> ((c = getchar()) == EOF) met?
>
> My perception is that you have to redirect your stdin to a file and
> then run this program.


No. Most systems have a key sequence that can signal end-of-file. Under
UNIX it is CTRL-D and under Windows, CTRL-Z. The sequence may have to
appear on it's own line to be effective.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-02-2007
James Fang said:

<snip>

> If you use the keyboard as the stdin source, how can the situation :
> ((c = getchar()) == EOF) met?


You have just asked (a very slight variant of) comp.lang.c FAQ 12.1b - see
http://c-faq.com for the answer.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting up instead of counting down edwardfredriks Javascript 6 09-07-2005 03:30 PM
DataGrid bound to DataTable containing blanks returns &nbsp; John A Grandy ASP .Net 2 11-21-2004 08:34 AM
just firing blanks !! mike Wireless Networking 7 10-02-2004 12:43 PM
Datagrid formatting dropping leading blanks tfs ASP .Net 1 06-28-2004 01:30 AM
RegularExpression validator that does not allow blanks John Hoge ASP .Net 2 05-23-2004 05:26 PM



Advertisments