Just a quick glance, but at line 67 you are outputting an element that is actually beyond the array. Size = 100, which means the elements of the array number from 0 to 99. inputarray[100] is actually outside of the array. Besides that, you have the output in a loop. What I think you meant to write, and which is standard practice, is actually
cout << inputarray[j]
.
Actually, I see the same error at line 63 as well. Also like was stated, if you want to iterate through the array the middle of the first for in fillString on line 60 should read i < size. And, while it's a minor formatting thing, you use different brace styles for each of the for loops. This makes it a bit harder to read. While the compiler will read both, you only need braces if your statement inside the loop is actually more than 1 statement. Otherwise the for loop at line 66 is fine without them since it's only 1 line (IE, you only need 1 semicolon) Also, you don't have to use int j for the second for loop, you can actually reuse int i since variables declared in the initialization expression only have a local scope of that loop. So after execution of the first for loop int i no longer exists and can be declared and initialized again in the second one. Only time you really have to use different variable names is if you have nested loops.
And if you are worried about empty files, you might as well add an error check to see if the file opened at all. Something like this works:
1 2
|
if (!(fin.is_open()))
exit(EXIT_FAILURE);
|
@Andy you would be right, but that's not what he wrote. What he has at line 60 is size < i, or i > size, which will never be true with i being initialized at 0 to begin with.