dither.c:16:9: error: too few arguments to function ‘fwrite’ ?can anyone help
-
Quote:
#include
#includeint main(int argc, char *argv[])
{
srand(12345);
// srand((unsigned int)time(NULL));float a = 5.0; int i; for (i=0;i<63530;i++) // condition for displaying number of the random number for here 63530 printf("%f\\n", ((float)rand()/(float)(RAND\_MAX)) \* a); //rand return integer value from 0 to RAND\_MAX(system dependent) FILE \*fout; //fout=fopen("random generated number","w"); const char \*text=("write this text to file"); fwrite(fout,((float)rand()/(float)(RAND\_MAX)) \* a,text); return 0;
}
-
Quote:
#include
#includeint main(int argc, char *argv[])
{
srand(12345);
// srand((unsigned int)time(NULL));float a = 5.0; int i; for (i=0;i<63530;i++) // condition for displaying number of the random number for here 63530 printf("%f\\n", ((float)rand()/(float)(RAND\_MAX)) \* a); //rand return integer value from 0 to RAND\_MAX(system dependent) FILE \*fout; //fout=fopen("random generated number","w"); const char \*text=("write this text to file"); fwrite(fout,((float)rand()/(float)(RAND\_MAX)) \* a,text); return 0;
}
See http://www.cplusplus.com/reference/cstdio/fwrite/[^] and check your passed parameters. You should have a look at the
fprintf
function which may be better for your purposes (writing to text file). -
Quote:
#include
#includeint main(int argc, char *argv[])
{
srand(12345);
// srand((unsigned int)time(NULL));float a = 5.0; int i; for (i=0;i<63530;i++) // condition for displaying number of the random number for here 63530 printf("%f\\n", ((float)rand()/(float)(RAND\_MAX)) \* a); //rand return integer value from 0 to RAND\_MAX(system dependent) FILE \*fout; //fout=fopen("random generated number","w"); const char \*text=("write this text to file"); fwrite(fout,((float)rand()/(float)(RAND\_MAX)) \* a,text); return 0;
}
-
See http://www.cplusplus.com/reference/cstdio/fwrite/[^] and check your passed parameters. You should have a look at the
fprintf
function which may be better for your purposes (writing to text file). -
You must read the documentation and understand the type and meaning of the different parameters. The
fwrite
function has four parameters but you are passing only three. Additionally, your parameters did not match the required types. The first parameter is a pointer to the binary data to be written. But you are passing the pointer to yourFILE
stream object. The second and third parameters specify the amount of data to be written and the last one is theFILE
pointer. To write a binary floating point value you might use:float f = ((float)rand()/(float)(RAND_MAX)) * a;
fwrite(&f, sizeof(float), 1, fout);To write data to a text file use
fprintf
likeprintf
passing theFILE
pointer as first parameter. -
You must read the documentation and understand the type and meaning of the different parameters. The
fwrite
function has four parameters but you are passing only three. Additionally, your parameters did not match the required types. The first parameter is a pointer to the binary data to be written. But you are passing the pointer to yourFILE
stream object. The second and third parameters specify the amount of data to be written and the last one is theFILE
pointer. To write a binary floating point value you might use:float f = ((float)rand()/(float)(RAND_MAX)) * a;
fwrite(&f, sizeof(float), 1, fout);To write data to a text file use
fprintf
likeprintf
passing theFILE
pointer as first parameter.