0

void reversefunction( const char *argv2, const char *argv3){

FILE *stream1=NULL;
FILE *stream2=NULL;

byteone table[HEADERLENGTH];
byteone numberofchannels;
byteone movebytes;

bytefour i;
bytefour sizeofdata;
bytefour var_towrite_infile;

stream1=fopen(argv2,"rb");
stream2=fopen(argv3,"wb+");

if(stream1==NULL){
    printf("\n.xX!- failed - to - open - file -!Xx.\n");
    exit(0);
}

if(stream2==NULL){
    printf("\n.xX!- failed - to - create - new - file -!Xx.\n");
    exit(0);
}

printf(".xX!- %s - opened - success -!Xx.\n",argv2);

fread(table,1,HEADERLENGTH,stream1);

//here starts the problem

numberofchannels=little_endian_to_bytefour((table+22),NUMCHANNELS);
sizeofdata=little_endian_to_bytefour((table+40),SUBCHUNK2SIZE);

//here ends the problem

fwrite(table,1,HEADERLENGTH,stream2);

movebytes=numberofchannels*2;

i=sizeofdata;
fseek(stream1,i,SEEK_SET);

while(i>=0){
    fread(&var_towrite_infile,4,movebytes,stream1);
    fwrite(&var_towrite_infile,4,movebytes,stream2);
    i=i-movebytes;
    fseek(stream1,i,SEEK_SET);
    printf("%d\n",i);
    printf("%d\n",sizeofdata);
    printf("%d\n",little_endian_to_bytefour((table+40),SUBCHUNK2SIZE));
    printf("-------------\n");
}

fclose(stream1);
fclose(stream2);
return;

}

So, when i'm trying to pass in variables numberofchannels and sizeofdata the return value of function little_endian_to_bytefour it doesn't pass nothing.And when i print the return value, it prints it correct. So why this happens ?

//screen of terminal

.
.
.

0
0
113920
-------------
0
0
113920
-------------
0
0
113920
-------------

.
.
.

//end of screen terminal

//additional imformation

typedef unsigned char byteone;

typedef unsigned short int bytetwo;

typedef unsigned int bytefour;



bytefour little_endian_to_bytefour(byteone *table, byteone bit_length){

    bytefour number=0;

    if(bit_length==2){
        number=table[1];
        number<<=8;
        number|=table[0];
    }
    else{
        number=table[3];
        number<<=8;
        number|=table[2];
        number<<=8;
        number|=table[1];
        number<<=8;
        number|=table[0];
    }

    return number;

}

small example/*

int myfunction(int var1, int var2)
{

  int var3;

  var3=var1+var2

  return var3;

}

int main(void){

  int zaza1;

  zaza1=myfunction(2,3);

  printf("the number is %d",zaza1);

return;
}

//terminal

the number is 0

//end of terminal

*/

4

2 回答 2

0
typedef unsigned char byteone;
typedef unsigned int bytefour;

bytefour little_endian_to_bytefour(byteone *table, byteone bit_length);

byteone numberofchannels;
byteone movebytes;

numberofchannels = little_endian_to_bytefour((table+22),NUMCHANNELS);
sizeofdata = little_endian_to_bytefour((table+40),SUBCHUNK2SIZE);
movebytes = numberofchannels * 2;

您正在为变量分配unsigned int返回值unsigned char,因此部分值将被丢弃。碰巧在这种情况下,剩下的部分为零。

目前尚不清楚这里打算发生什么。您只是想将变量声明为具有类型bytefour吗?

如果你在编译时启用了警告,你应该已经被警告过这个潜在的问题。

于 2013-06-14T19:30:05.153 回答
0

您可能会混淆var3您在 中声明和返回的myfunction,以及arg3获得 的值的var1+var2

也就是说,您返回一个未初始化的变量var3,以防万一。

于 2013-06-14T18:13:36.267 回答