- #1
sandy.bridge
- 798
- 1
Homework Statement
Hello all. I have a function that is supposed to decode a string of integers and characters into an image. The function is not working 100%, and I cannot seem to figure out why.
Here is my code:
PHP:
void part5(char F[80][80], int Y, int Z) // function for q1p5.
{
cin >> noskipws;
int num_pixels = Y*Z;
int num_pixels_decoded = 0;
while (num_pixels_decoded < num_pixels)
{
int N, i = 0, count = 0;
char ch; char dy; while(i < Y){
cin >> N >> dy >> ch;
for (int k=0; k<N; k++)
{
F[i][k]=ch; cout << F[i][k];
count++; num_pixels_decoded++;
if (count == Z){cout << endl;i++; count = 0;}
}
}
cout << endl;
for(int x = 0; x < Y; x++)
{
for(int y = 0; y < Z; y++)
{
cout << F[x][y];
}
}cin >> skipws;
return;}
}
I believe the issue has something to do with assigning the array. The first cout << F[k] outputs the image perfectly; however, the second loop (which I made just to ensure that the array was indeed saving correctly), is not giving anything to the console. That is, cout << F[x][y]; does not do a thing.As an example:
If I input :22: 1:,1:;1:-1:.42: 1:,2:(2:-1:\1:)1:.39: 1:/8: 1:\37: 1:|10: 1:|36: 1:|10: 1:|35: 1:(1:,1:'1:"1:`1:.2: 1:,1:'1:"1:`1:.1:)34: 1::5: 1:\1:/5: 1:;34: 1:`1:.12: 1:,1:'1:`1:.2: 11:,1:'34: 1:(1:|1:`1:>1:'1:`2:-1:'1:`1:<1:'1:|1:)12: 1:,1:-1:,7: 1:,1:.11: 1:|1:/8: 1:\1:|9: 1:,1:-1:.1:/1: 1:/6: 1:_1: 1:|1: 1:\1:,1:-1:.7: 1:(10: 1:)8: 1:|1: 1:`1:-1:'1:`2:-1:.3: 1:(1: 1:`1:'1: 1:(1:_1:/1:|2:_6: 1:\3: 1:(13: 1:/7: 1:,1:-1:'5: 1:,1:-1:'4: 1:;9: 1:)4: 1:,1:|1:`1:.2: 1:-1: 1:,1:'1:|1:.6: 1:`1:-1:.3: 1:)1: 1:\6: 1:|1: 1:(4: 1:,1:-1:'3: 1:_1:/1: 1:`1:-1:.1:`2:"1:'1:,1:-1:'1: 1:\3:-1:.3: 1:/6: 1:;5: 1:|5: 1:|3: 1:,1:-1:'2: 1:\2: 1:/1:\2: 1:/1: 1:\2: 1:|3: 1:|2:-1:/7: 1:|5: 1:|5: 1:|1:_1:,1:|4: 1:/1: 1:\1:/2: 1:\1:/3: 1:\1:/1:\3: 1:|10: 1:|5: 1:|5: 1:`2: 1:\3: 1:|14: 1:\2: 1:/8: 1:,1:'6: 1:|9: 1:\2: 1:|14: 1:|1: 1:/6: 1:_1:,1:'8: 1::10: 1:\1: 1:,14: 1:`1:/6:-1:'12: 1:`1:-1:.3:_1:,3:-1:'1:)16: 1:`1:.27: 1:,1:'19: 1:\25: 1:/22: 1:\23: 1::24: 1::22: 1:|22: 1:_1:,1:|23: 1:\2:-1:.3:_9: 2:_1:,2:-1:'1: 1:;25: 1:`1:.4: 1:`7:"1:'6: 1:,1:'27: 1:|18: 1:|28: 1:|6: 1:.4:_1:,6: 1:|28: 1:|9: 1:|8: 1:|28: 1:|9: 1:|8: 1:|28: 1:|9: 1:|8: 1:|28: 1:|9: 1:|8: 1:|28: 1:|9: 1:|8: 1:|18: 1:-1:h2:r1:-5: 1:|9: 1:|8: 1:|28: 1:|9: 1:|8: 1:|28: 1:|1:-1:.5:_1:,1:-1:|1:-1:.4:_1:,1:-1:|28: 1:|1:_8: 1:|1:_7: 1:|26: 1:,1:'2: 1:`6:-1:'1:|1: 1:`5:-1:'1: 1:\24: 1:/11: 1:_1:|1:_9: 1:\23: 1:`2:-1:.5:_1:,1:-1:'3: 1:`1:-1:.3:_1:,1:-1:'60: . Then the first cout << produces an image of Homer Simpson. The second cout does nothing at all.