-
Also, you need to move forward in your histogram so that you don't print the same four entries over and over and over again. If you need to use fwrite, then you should be adding 4 to histogram every time through the loop. (Not to *histogram, but to histogram). If you end up using fprintf, then you'll need to use an index on histogram (like histogram[i]) that should move forward.
-
Code:
int intarray[ X ] = { filledwithcolor }, *intptr = intarray;
char chararray[ (X/COLS) * (1+sizeof(int)) ] = {0}, *charptr = chararray;
while( charptr < chararray + sizeof( chararray ) )
{
size_t col;
for( col = 0; col < COLS; col++ )
*((int*)charptr++) = *intptr++;
*charptr++ = '\n';
}
fwrite( chararray, sizeof( chararray ), 1, fp );
:shiftyeyes:
[edit]
that cast / increment is bugging me. Let's go with this:
Code:
union u
{
char *cp;
int *ip;
} hah;
int intarray[ X ] = { filledwithcolor }, *intptr = intarray;
char chararray[ (X/COLS) * (1+sizeof(int)) ] = {0};
for( hah.cp = chararray; hah.cp < chararray + sizeof( chararray ); *hah.cp++ = '\n' )
{
size_t col;
for( col = 0; col < COLS; col++ )
*(hah.ip++) = *intptr++;
}
fwrite( chararray, sizeof( chararray ), 1, fp );
If a union isn't the right answer, you're asking the wrong question!
[/edit]
Quzah.
-
fprintf worked! =D
program is officially done and fully functional!! /victorydance
thanks, fellow programmers, i couldnt have done with without you!!!! <3 <3 <3 <3 <3