How can I cuont The number of words in a file ? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How can I cuont The number of words in a file ?

rambosoftrambosoft Posts: 2Member
How can I cuont The number of words in a file ?Using TASM

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]I forgot TASM... sorry, but here is some pseudo-code:[/color]
    [code]
    open file
    nbytes = get file size
    token = 0
    nwords = 0

    repeat 'nbytes' times
    {
    c = read one character from file
    if (c is a word character)
    {
    ++token
    if (token is 1) ++nwords
    }
    else
    {
    token=0
    }
    }
    ;
    ; Function to check if c is a word character
    ;
    bool IsWordChar (c)
    {
    if (c is underscore) return true;
    if (c is digit) return true;
    if (c is lowercase character) return true;
    if (c is uppercase character) return true;
    return false;
    }
    [/code]
    [color=Blue]FASM is so much easier to use.[/color]
  • rambosoftrambosoft Posts: 2Member
    Thanks any way
  • m34tb34tm34tb34t Posts: 25Member
    filesize in bytes divided by 2 == number of words in file...
    LOL but seriously.
    It depends on your definition of a word and on what type of file. You could simply scan for the value 20h (space) and count every one you see. But that would only work in very limited situations. AsmGuru got the general purpose algorithm up already...
  • m34tb34tm34tb34t Posts: 25Member
    The best solution will depend on the type of file you are counting words from and how you want to define a word. ASCII vs. Unicode. MS-Word docs vs. PDF files. It can get quite elaborate.

    ASCII is the easiest to count groups of english letters with.

    I would inc my counter on the first encounter of A-Z or a-z and skip everything else until I found a space, then skip any space characters until I encountered another alphabet character. Inc my counter again, rinse and repeat 'till you reach the end of the file.
  • avidwanavidwan Posts: 4Member
    how to write reverse a string program in c?
    how to write Reverse string program source code using pointers in c programming language..?
    Armstrong numbers in c?
    palindrome numbers program in c?

    ***************************************************************



    [link=http://www.programmingpad.com]Programming Pad.com[/link]


    ***************************************************************
  • avidwanavidwan Posts: 4Member
    how to write reverse a string program in c?
    how to write Reverse string program source code using pointers in c programming language..?
    Armstrong numbers in c?
    palindrome numbers program in c?

    ***************************************************************



    [link=http://www.programmingpad.com]Programming Pad.com[/link]


    ***************************************************************
  • avidwanavidwan Posts: 4Member
    how to write reverse a string program in c?
    how to write Reverse string program source code using pointers in c programming language..?
    Armstrong numbers in c?
    palindrome numbers program in c?

    ***************************************************************



    [link=http://www.programmingpad.com]Programming Pad.com[/link]


    ***************************************************************
Sign In or Register to comment.