Code:
const TESTDATA[] ATTRIBUTE_ALIGN( 32 ) =
{
0, 0, 219, 61, -289, -491, -475, -367,
-549, -1115, -1087, -857, -1183, -712, 373, 1147,
2733, 4312, 3440, 1111, -513, -1840, -2080, -139,
943, -227, -1105, -1045, -1185, -1391, -984, -549,
-685, -803, -1072, -1817, -2131, -2144, -2821, -3931,
-5181, -6601, -7507, -7068, -5316, -2864, -797, -296,
-488, -123, 8, -1164, -2801, -2881, -2437, -3100,
-2997, -1700, -783, -155, 408, 623, 779, 224,
-1977, -4167, -4763, -4504, -3864, -3199, -2891, -2051,
119, 2379, 3829, 6088, 8829, 10232, 11181, 11582,
10096, 7707, 5892, 3763, 216, -2027, -641, 1795,
3753, 5995, 7212, 6048, 4051, 3623, 4205, 4709,
6556, 9495, 11444, 12430, 12889, 12228, 10732, 9289,
}
Above, the result I seek (as written to afile)
Code:
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#include "stdafx.h"
int main(int argc, char* argv[])
{
FILE *fp,*of;
int num;
char counter=0,a,b;
if (argc != 4 && argc != 5) {
puts("Usage: CONVERTER inputfile.RAW output.c structurename [flip]");
return 0;
}
fp=fopen((const char *)argv[1],(const char *)"rb");
if (fp) {
of=fopen((const char *)argv[2],(const char *)"w");
if (of) {
fprintf(of,"\n#include \"TEST.h\"\n\nconst s16 %s[] ATTRIBUTE_ALIGN( 32 ) =\n{\n",argv[3]);
do {
a=0;
b=0;
if (!(feof(fp))) a=fgetc(fp);
if (!(feof(fp))) b=fgetc(fp);
num=0;
if (argc==4) { //don't flip
num=(a*256+b);
if (num > 32767) num=(num-32768)*-1;
}
else {
num=(b*256+a);
if (num > 32767) num=(num-32768)*-1;
}
if (counter != 0) fprintf(of,", %7d",num);
else fprintf(of," %7d",num);
counter++;
if (counter==8) {
if (!(feof(fp))) fprintf(of,",\n");
else fprintf(of,"\n");
counter=0;
}
} while (!(feof(fp)));
if (counter != 0) fprintf(of,"\n");
fprintf(of,"\n};");
fclose(of);
}
else {
puts("Error: could not open outputfile");
}
fclose(fp);
}
else {
puts("Error: could not open inputfile");
}
return 0;
}
Where did I go WRONG?? the converter converts data OK, but the result exceeds 32768, the limit ??