I'm trying to write a code that pulls from a txt file (input.txt) that looks like this:
1,2,3
Hello
2,3,4
Music
1,3,4
Dodie
3,0,1
Kitty
5,1,0
Cheese
And prints out the word as many times as the numbers above it added up. So the first one would be 1+2+3=6, so it would print: Hello,Hello,Hello,Hello,Hello,Hello
Current Output:
1,2,3
1,2,3
1,2,3
1,2,3
1,2,3
Hello
Hello
Hello
Hello
Hello
2,3,4
2,3,4
2,3,4
2,3,4
2,3,4
Music
Music
Music
Music
Music
1,3,4
1,3,4
1,3,4
1,3,4
1,3,4
Dodie
Dodie
Dodie
Dodie
Dodie
3,0,1
3,0,1
3,0,1
3,0,1
3,0,1
Kitty
Kitty
Kitty
Kitty
Kitty
5,1,0
5,1,0
5,1,0
5,1,0
5,1,0
Cheese
Cheese
Cheese
Cheese
Cheese
I can't figure out how to pull a specific line separately/separate the lines of the txt file.
Current code (we aren't supposed to use namespace std, but I was trying to figure out the basics first. It is also supposed to print into another txt file called output.txt):
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int MAX=7;
int main() {
ifstream inFile ("input.txt");
char input[MAX];
while (inFile) {
int num = 5;
inFile.getline(input, MAX);
for(int n = 0; n < num; n++) {
printf(input);
printf("\n");
} // end for
} // end while
inFile.close();
return 0;
}