Creating a list of words

This is a discussion on Creating a list of words within the C Programming forums, part of the General Programming Boards category; Hi, need some help with this one. Here is the question: Compose an algorithm for a program that creates a ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    8

    Creating a list of words

    Hi, need some help with this one. Here is the question:

    Compose an algorithm for a program that creates a list of words encountered when reading a series of text files. Write a program to open, and subsequently close, each input file, terminating should an attempt to open any file fail. Derive the file names from the command line.

    I've heard of the "argc" and "argv" features to do this, but i have never used them before and have no idea how they work. Is someone able to point me in the right direction?

    All help is greatly appreicated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,268
    I've heard of the "argc" and "argv" features to do this, but i have never used them before and have no idea how they work. Is someone able to point me in the right direction?
    We have a tutorial/FAQ on the topic.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    What you trying to do create an unique array of words in the files and a count of how many times the word showed up in the files listed?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main ( int argc, char *argv[] )
    {
        int files = argc-1, i = 0;
        FILE *file;
    
        for(i = 1; i <= files; i++)
        {
                    printf("opening FILE filename = &#37;s\n",argv[i]);
    
                    if ( (file = fopen( argv[i], "r")) == NULL )
                    {
                            fprintf(stderr, "Can't Open file %s\n", argv[i]);
                            exit(0);
                     }
                    fclose( file );
        }
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    1
    Hi, I am working on something similar to this and have more or less the same code as above.

    What i am having difficulty with is alphabetically sorting the text file, i am experimenting with qsort without much sucess.

    Thanks in advance if anyone can help.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,268
    huntley, start your own thread detailing your problem, your attempt at a solution, and how does it not work.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a Sorted Linked List, Help Please!
    By larry_2k4 in forum C Programming
    Replies: 4
    Last Post: 04-28-2009, 02:12 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 07:16 PM
  4. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  5. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM

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