problem with fscanf in Pocket PC
-
hello,Reading a text file of integers with this code for (k=0;k<256; k++) { for (l=0;l<12; l++) fscanf(fmel,"%d",&melCdb->vq[k][l]); for(l=0;l<12;l++) { fscanf(fmel,"%d",&aux); // melCdb->cov[k][l]=2*aux; } } the program breaks when k=16 without any reason in fscanf(fmel,"%d",&melCdb->vq[k][l]); there is more than 10mb of free memory in the Pocket PC and this code works properly with the same file in in the desktop with VC++ 6.0. Somebody knows what is the problem? Thanks
-
hello,Reading a text file of integers with this code for (k=0;k<256; k++) { for (l=0;l<12; l++) fscanf(fmel,"%d",&melCdb->vq[k][l]); for(l=0;l<12;l++) { fscanf(fmel,"%d",&aux); // melCdb->cov[k][l]=2*aux; } } the program breaks when k=16 without any reason in fscanf(fmel,"%d",&melCdb->vq[k][l]); there is more than 10mb of free memory in the Pocket PC and this code works properly with the same file in in the desktop with VC++ 6.0. Somebody knows what is the problem? Thanks
Try this:
...
for (l=0;l<12; l++)
{
int value;
fscanf(fmel,"%d",&value);
melCdb->vq[k][l] = value;
...If this doesn't help: How do you create the array
melCdb->vq[k][l]
? Please show us your source code! -- Cheers, Daniel ;) -
Try this:
...
for (l=0;l<12; l++)
{
int value;
fscanf(fmel,"%d",&value);
melCdb->vq[k][l] = value;
...If this doesn't help: How do you create the array
melCdb->vq[k][l]
? Please show us your source code! -- Cheers, Daniel ;)Hello, the source code is melCdb->vq=(long **)malloc((256)*sizeof(long *)); for (k=0;k<256; k++) { melCdb->vq[k]=(long *)malloc((12)*sizeof(long)); } for (k=0;k<256; k++) { for (l=0;l<12; l++) fscanf(fmel,"%d",&melCdb->vq[k][l]); for(l=0;l<12;l++) { fscanf(fmel,"%d",&aux); } } I have already checked that mallocs give dinamic memory correctly. Thanks for your help.
-
Hello, the source code is melCdb->vq=(long **)malloc((256)*sizeof(long *)); for (k=0;k<256; k++) { melCdb->vq[k]=(long *)malloc((12)*sizeof(long)); } for (k=0;k<256; k++) { for (l=0;l<12; l++) fscanf(fmel,"%d",&melCdb->vq[k][l]); for(l=0;l<12;l++) { fscanf(fmel,"%d",&aux); } } I have already checked that mallocs give dinamic memory correctly. Thanks for your help.
Try this:
for (k=0;k<256;k++)
{
for (l=0;l<12;l++)
{
long* pl = melCdb->vq[k];
fscanf(fmel,"%ld",&pl[l]);
}
}Don't forget to use %ld in the
fscanf
function, because this are the right syntax for along
. -- Cheers, Daniel ;)