Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. dither.c:16:9: error: too few arguments to function ‘fwrite’ ?can anyone help

dither.c:16:9: error: too few arguments to function ‘fwrite’ ?can anyone help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlounge
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mybm1
    wrote on last edited by
    #1

    Quote:

    #include
    #include

    int 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;
    

    }

    J M 2 Replies Last reply
    0
    • M mybm1

      Quote:

      #include
      #include

      int 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;
      

      }

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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).

      M 1 Reply Last reply
      0
      • M mybm1

        Quote:

        #include
        #include

        int 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;
        

        }

        M Offline
        M Offline
        mybm1
        wrote on last edited by
        #3

        even though I pass fwrite(fout,((float)rand()/(float)(RAND_MAX)) *a,text); it is generating the file.txt but null value on it..

        1 Reply Last reply
        0
        • J Jochen Arndt

          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).

          M Offline
          M Offline
          mybm1
          wrote on last edited by
          #4

          same problem no change :(

          J 1 Reply Last reply
          0
          • M mybm1

            same problem no change :(

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #5

            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 your FILE stream object. The second and third parameters specify the amount of data to be written and the last one is the FILE 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 like printf passing the FILE pointer as first parameter.

            M 1 Reply Last reply
            0
            • J Jochen Arndt

              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 your FILE stream object. The second and third parameters specify the amount of data to be written and the last one is the FILE 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 like printf passing the FILE pointer as first parameter.

              M Offline
              M Offline
              mybm1
              wrote on last edited by
              #6

              thank you finally I got it..

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups