#include <stdio.h>
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
int main(int argc, char** argv)
{
// Declarations
std::string str;
std::vector<std::string> myVector;
std::string inputString=new string (argv[1]);
// Open file and stores words in a vector
std::ifstream myFile;
myFile.open (argv[2]);
while (myFile.good()){
std::getline(myFile,str);
myVector.push_back(str);
}
myFile.close();
// Ask for input string from user and convert to upper case
//std::cout << "Please enter a word to search" << std::endl;
//std::cin >> inputString;
//inputString = argv[1];
for(int j=0;j<inputString.length();j++){
inputString[j] = toupper(inputString[j]);
}
// Check if word is in the Vector and return count as line number
// if word is not in the list the bool will remain false.
// The bool is checked after the loop
bool wordInList=false;
int lineCount=1; // Start at line one
for(int i=0;i<myVector.size();i++){
if(inputString == myVector[i]){
std::cout << lineCount << std::endl;
wordInList=true;
}
lineCount++;
}
if(wordInList == false){
std::cout << 0 << std::endl;
}
}
I have messed with it slightly. Basically it works fine on my machine. Takes an input file names myfile.txt from my machine and then a word from the user and outputs the number of line the word is on or 0 if word isnt there.
My program works fine, however....
On a submission website obviously I cant use myFile.txt from my machine and same with inputting a word. So I use argc and argv pointers as seen above. Am I using them wrong or what?
This silly website keeps telling me im wrong and it aint working
This post has been edited by Kohana: 06 December 2010 - 07:55 PM

New Topic/Question
Reply




MultiQuote




|