Copy User Input to User Input

I have found and edited this so I think It would work. The only problem Is is when I Run the program Both input and Output end up being empty. (Okb. Instead of 45kb) What's the matter?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
using namespace std;

int main (void)
{
          size_t len  ;
  string a;
  string b;
  cout << "What's The File";
  getline (cin, a);
  cout << "What is the Destination";
  getline (cin, b);
        FILE* in = fopen( a.c_str(), "wb" ) ;
        FILE* out = fopen( b.c_str(), "wb" ) ;
              char buffer[BUFSIZ] = { '\0' } ;
                    if( in == NULL || out == NULL )
      {
      perror( "An error occured while opening files!!!" ) ;
      in = out = 0 ;
      }
      else // add this else clause
      {
      while( (len = fread( buffer, 1, BUFSIZ, in)) > 0 )
      {
                 fwrite( buffer, 1, (BUFSIZ, len), out ) ;
      }
       
      fclose(in) ;
      fclose(out) ;
       
      system("PAUSE");
  return 0;
}}
Your logic has gone a bit wrong here:
1
2
  FILE* in = fopen( a.c_str(), "wb" ) ;
  FILE* out = fopen( b.c_str(), "wb" ) ;
When you say "I have found this code and edited it" than makes me think this is a copy paste from our good buddy Google?

Drop the "FILE* in\out..." stuff and stick with the fstream library, it's much easier to read. The way you are trying is valid but I think it would be easier for you to #include <fstream> (pun intended :D).
Topic archived. No new replies allowed.