can any one


 
Thread Tools Search this Thread
Top Forums Programming can any one
# 1  
Old 05-29-2005
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.
# 2  
Old 05-30-2005
Is this homework? And even if it is, can I give a hint on how to go about this?
# 3  
Old 05-30-2005
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  
Old 05-30-2005
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  
Old 06-04-2005
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  
Old 06-10-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question