Removing comments and spaces from a program HELP

Hello, C++ beginner here. I am trying to write a program that will remove all extraneous white spaces, comments(both types: /* */ and //), and new line characters from another piece of code. (Seems redundant, but it's an assignment). I'm unsure of how to go about doing this.
So far, I am able to read in the file removing any extra spaces. Any idea on how I would go about removing comments? Also, my professor said that the new code should all be on one line and should be able to compile the same way as the original source code. Not sure how that works...
Anyway, this is an intro course I am taking, so I am not permitted to use things like pointers or classes. This is what I have so far:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cctype>
#include <string> 

 using namespace std;

 void processFiles(const char *, const char *); 
 
/******************************************************************************/
 int main()
 {
 string inputFile, outputFile;
 cout << "Enter the name of the input file: ";
 cin >> inputFile;
 cout << "Enter the name of the output file: ";
 cin >> outputFile;

 processFiles(inputFile.c_str(), outputFile.c_str());

 return 0;
 } //end main
/******************************************************************************/

 void processFiles(const char *infile, const char *outfile)
{
 char c;// just in case I decide to read in the file character by character
        // instead of the method used below
 string word;

 ifstream input;
 ofstream output;

 input.open(infile);
output.open(outfile);

 if (!input.is_open()) {
 cout << "\nERROR: could not find the input file: " << infile << endl;
 exit(1);
 }

 if (!output.is_open()) {
 cout << "\nERROR: could not find the output file: " << outfile << endl;
 exit(1);
 }
 
 input >> word;
    while(!input.eof()){
            output << word << " ";
            input >> word;
    }
    input.close();
}


So what this does so far is copy the input file(a cpp file) on to one line with one blank between each word. I was considering using getline() or input.get to read in the characters.If anyone has a useful method to use to read in the file and remove comments and extra spaces I would appreciate it.
Topic archived. No new replies allowed.