Go Back   The UNIX and Linux Forums > Top Forums > Programming
.
google site



Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2005
Registered User
 

Join Date: May 2005
Location: CHENNAI
Posts: 5
can any one

please help me to find the number character,word,lines,spaces,tabs
new lines in a given text.using c-language in linux.
Sponsored Links
  #2 (permalink)  
Old 05-30-2005
blowtorch's Avatar
AFK
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,351
Is this homework? And even if it is, can I give a hint on how to go about this?
  #3 (permalink)  
Old 05-30-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
parvathy, please make sure that you have read our rules. Your first two threads were a crosspost and rule 4 says:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

And this question does look like a homework question which is also against the rules. But I'm not sure. Still, blowtorch, homework or no, if you want to give a few hints, go ahead.
  #4 (permalink)  
Old 05-30-2005
blowtorch's Avatar
AFK
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,351
Ok Perderabo.
Parvathy, read the file one character at a time, and compare the character that you read to "\n" for newlines, "\t" for tabs and the ascii value of space for counting the number of spaces. Also, keep a counters for each char that you read - this will give you the number of characters. Keep two more counters that you will update when:
1. You hit a space or a newline - this will count the number of words.
2. When you hit a newline - this will count the number of lines.

Cheers!
  #5 (permalink)  
Old 06-04-2005
Registered User
 

Join Date: Jun 2005
Posts: 1
Quote:
Originally Posted by blowtorch
Keep two more counters that you will update when:
1. You hit a space or a newline - this will count the number of words.
Cheers!
Reading some of your other replies I sure you knew this and I'm guessing you left him a little more work to do for himself since he's likely to find that his word count is off. Since it is probably too late for the homework assignment I don't feel bad about filling in a little more here.

He really needs to check for isspace() not just a space or a newline - especially since the initial question indicates the file is likely to include tab characters. He also needs to hold the result of the previous character evaluation so that each one of a series of space characters does not increment the word counter.
  #6 (permalink)  
Old 06-10-2005
yogesh_powar's Avatar
Registered User
 

Join Date: Jun 2005
Location: satara
Posts: 37
why dont you a buy book of DANIS RICHI its a good book and all the developnment of c is because of that book.

still some help

read the file
by read() system call
then compare the character by character
and increment.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 06:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0