counting the number of words in a file

This is a discussion on counting the number of words in a file within the C Programming forums, part of the General Programming Boards category; Hi I have file called test.txt which looks like this: aaa , bb.ccc I need my program to count the ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    counting the number of words in a file

    Hi

    I have file called test.txt which looks like this:

    aaa , bb.ccc

    I need my program to count the number of words in the file, but not to count the spaces, comma's, fullstops etc. For example there is 3 words in the above file.

    I know fscanf(fptr, "%s", name) will read a string up to a space or a newline. fptr is my FILE pointer and name is an array of char.

    Can someone please help?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    A different option is using fgetc to get a byte from the file. Rembember when a word starts and increase a counter when the word has ended.

  3. #3
    Unregistered
    Guest
    you wouldn't be chaeting on your c programming assignment at t.u. would you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Counting Number of Words in a Text File Using C
    By wvu2005 in forum C Programming
    Replies: 16
    Last Post: 09-27-2005, 11:45 AM
  3. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 09:01 AM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21