title: C++ Make a file of a specific size
body: <p>Here is my current problem: I am trying to create a file of x MB in C++. The user will enter in the file name then enter in a number between 5 and 10 for the size of the file they want created. Later on in this project i'm gonna do other things with it but I'm stuck on the first step of creating the darn thing.</p>
  
  <p>My problem code (so far):</p>
  
  <pre><code>        char empty[1024];
          for(int i = 0; i &lt; 1024; i++)
          {
              empty[i] = 0;
          }
  
          fileSystem = fopen(argv[1], "w+");
  
  
          for(int i = 0; i &lt; 1024*fileSize; i++){
              int temp = fputs(empty, fileSystem);
              if(temp &gt; -1){
                  //Sucess!
              }
              else{
                  cout&lt;&lt;"error"&lt;&lt;endl;
              }
          }
  </code></pre>
  
  <p>Now if i'm doing my math correctly 1 char is 1byte. There are 1024 bytes in 1KB and 1024KB in a MB. So if I wanted a 2 MB file, i'd have to write 1024*1024*2 bytes to this file. Yes?</p>
  
  <p>I don't encounter any errors but I end up with an file of 0 bytes... I'm not sure what I'm doing wrong here so any help would be greatly appreciated!</p>
  
  <p>Thanks!</p>