Word comparison - Vectors /Getopt

This is a discussion on Word comparison - Vectors /Getopt within the C++ Programming forums, part of the General Programming Boards category; Please Help!!! My understanding of getopt is very limited. I do however realise that argv[0] is the exe file, argv[1] ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    2

    Word comparison - Vectors /Getopt

    Please Help!!!

    My understanding of getopt is very limited.
    I do however realise that argv[0] is the exe file, argv[1] is the option, argv[2] is the word to compare and argv[3] is the dictionary or document I want to search(file .txt).
    I'm trying to set a pointer to the dictionary and then iterate through it to see if there is a match with the argv[2] (input word) to the text file, and if there is a match out put the argv[2] word.
    Below is my current code that has errors
    main.cpp:61: error: no match for 'operator==' in 'list == *(argv + 12u)'
    main.cpp:64: error: no match for 'operator*' in '*list'
    Any help would be greatly appreciated.

    Code:
    #include <cstdlib>
    #include <unistd.h>
    #include <vector>
    #include <iostream>
    #include <string>
    #include <iterator>
    
    
    using namespace std;
    
    
    int main(int argc, char** argv) {
    
    
        enum {
            WHOLE, PREFIX, SUFFIX, ANYWHERE, EMBEDDED
        } mode = WHOLE;
        bool jumble = false;
        bool ignore_case = false;
        bool invert = false;
        string length = "0,0";
        int c;
        string input;
        vector <string> list;
        vector <string>::iterator i;
    
    
        while ((c = getopt(argc, argv, ":wpsaejivn:")) != -1) {
            switch (c) {
                case 'w': mode = WHOLE;
                    break;
                case 'p': mode = PREFIX;
                    break;
                case 's': mode = SUFFIX;
                    break;
                case 'a': mode = ANYWHERE;
                    break;
                case 'e': mode = EMBEDDED;
                    break;
                case 'j': jumble = true;
                    break;
                case 'i': ignore_case = true;
                    break;
                case 'v': invert = true;
                    break;
                case 'n': length = optarg;
                    break;
                default: WHOLE;
                    break;
            }
        }
        argc -= optind;
        argv += optind;
    
    
        switch (mode) {
            case WHOLE:
                while(argc != -1){
                    list == argv[3];
                    for(i == list.begin(); i != list.end(); i++)
                    if(argv[1] == argv[3]){
                        cout << *list << endl;
                    }else cout << "Did not work again" << endl;
                }           
                    
        }
        return 0;
    }


  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > list == argv[3];
    You need to
    - open the filename (in argv[3])
    - read each line, and store each line in your 'list' vector
    - close the file

    > if(argv[1] == argv[3])
    These are two pointers to 'C' style strings.
    You need to use strcmp() to compare these.


    > cout << *list << endl;
    You need to output the iterator, not the list
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 10-23-2011, 07:17 PM
  2. getopt
    By Dr Saucie in forum C Programming
    Replies: 1
    Last Post: 03-11-2010, 11:00 AM
  3. std::string comparison versus int comparison
    By leeor_net in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2009, 07:28 AM
  4. getopt help
    By wuzzo87 in forum C Programming
    Replies: 12
    Last Post: 04-09-2007, 03:16 AM
  5. Word Comparison Error
    By DeepFyre in forum C++ Programming
    Replies: 9
    Last Post: 01-01-2005, 09:00 AM

Tags for this Thread


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