If statements not working
Mar 19, 2014 at 8:20pm UTC
I am making a multiple file program. I need to get commands from a input file and make the program do different things depending on the commands. Whenever I compare the string from the file the program doesn't go into the if statements and it repeats the strings that it has already gone through.
Here is the main file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include "Loanstuff.h"
#include "Savevalues.h"
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
void fillVectorWithPointers(vector<Savevalues *> &list);
int main (){
string check;
Loanstuff loan1;
ifstream infile;
vector<Savevalues *> loanlist;
fillVectorWithPointers(loanlist);
vector<string *> stringList;
string nextLine, line;
infile.open("input.txt" );
while (getline(infile, nextLine)){
loan1.parseString(nextLine, stringList);
for (unsigned int i=0; i<stringList.size(); ++i){
cout<<*stringList[i]<<endl;
}
*stringList[1]==line;
if (line=="cp" ){
cout<<"sadasdas" << endl;}
else if (line=="n" ){
*stringList[2]=check;
cout<< atof(check.c_str());
}
else if (*stringList[1]=="mi" ){
}
else if (*stringList[1]=="mp" ){
}
else if (*stringList[1]=="pf" ){
}
else if (*stringList[1]=="rp" ){
}
else if (*stringList[1]=="sh" ){
}
else if (*stringList[1]=="//" ){
}
else {
cout<<"Error in command, going to next line" <<endl;
}
}
loanlist[0]->printinfo();
return 0;
}
void fillVectorWithPointers(vector<Savevalues *> &loanlist)
{
for (int i=0; i < 10; ++i)
loanlist.push_back(new Savevalues());
}
Here is the file related to it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
#include "Loanstuff.h"
#include "Savevalues.h"
#include<vector>
#include<cstring>
using namespace std;
Loanstuff::Loanstuff()
{
}
void Loanstuff::printpayments(){
}
void Loanstuff::printtable(){
}
void Loanstuff::parseString(string theLine, vector<string *> &theList)
{
char buffer[theLine.length()+1];
theLine.copy(buffer, theLine.length(), 0);
buffer[theLine.length()]='\0' ;
char * token;
token = strtok(buffer, ",\t " );
while (token != NULL){
theList.push_back(new string(token));
token = strtok(NULL, ",\t " );}
}
Example input file:
Topic archived. No new replies allowed.