I am a complete newbie to C++, and almost a comlete newbie to programming. This site is a godsend, though.
I have been going through the tutorials and making projects that utilize the new things that I have learned. I have gotten through File I/O, and my newest projects is making a Mad-Libs-like program. I have gotten everything down excepting the last step, and for the life of me I can't figure where I'm going wrong.
I have made a small program that encapsulates the problem and allows for greater readability and all. I will give you the content of the two text files the program inputs from and the code of the small program.
The program is meant to take the content of original.txt and, on certain words replace them with words from marker.txt
I have been hitting an infinite loop. Check below to see where.
Text of original.txt:
once upon an adjective dog , a cat decided to verb . done
So the final output in final.txt should be:
Text of marker.txt:
4 odd 11 eat done
once upon an odd dog , a cat decided to eat .
int spotter = 0; //counts the iteration of first while loop
int conv; //used for a conversion later
int indicator = 0; //used as a boolean
//my inputs - see above in post for contents
while(strcmpi(original, "done")) //runs until original.txt hits word "done"
spotter = spotter + 1;
indicator = 0;
marker.open("markers.txt"); //resets marker to beginning
while(strcmpi(mark, "done")) //runs until marker.txt hits word "done"
marker>>mark; //Alright, I have tinkered a bit already, and I'm pretty sure
//that this is where the problem lies. It just doesn't seem to
//be inputting anything. I'm stumped.
//This block of code is supposed to convert the string of numeric characters into integers
//In my Intro to CS class we use Java, and for this we have Integer.parseInt, so if
//a similar function exists in C++, let me know. But I don't think this is where the problem is.
if(strlen(mark) == 2)
conv = ((((int)mark - 48) * 10) + ((int)mark - 48));
else if(strlen(mark) == 3)
conv = ((((int)mark - 48) * 100) + (((int)mark - 48) * 10) + (((int)mark - 48)));
conv = ((int)mark - 48);
//So if the number in marker.txt is the iteration we are on...
if(conv == spotter)
marker>>mark; //1. takes next word out of marker.txt
starter>>original; //2. skips next word from original.txt
final<<mark; //3. inputs string from step 1
indicator = 1; //4. uses indicator like a boolean, see below
if(indicator == 0) //if nothing happened in above loop...
final<<original; //input next word from original.txt and continue.