Displaying character arrays

closed account (oy721hU5)
Hello everyone,

This program asks the user to enter a number. These number corresponds to the number of 'words' that the user would like to store on a .txt file. These words must then be displayed under the user's input. Basically, the text file must be read to display the output. I am having trouble with that. Please assist me.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 #include "file.h"

int main()
{
	CFile MyFile;

	MyFile.OpenTheFile();
	MyFile.WriteToTheFile();
	MyFile.ReadToTheScreen();
	MyFile.CloseTheFile();


	MyFile.NormalTermination();

	return 0;
}

//header file
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <fstream>

using namespace std;

class CFile
{
	public:
		CFile(){}

		// start of facilitators
		void ClearTheScreen()
		{
			system("cls");
		}
		void NormalTermination()
		{
			cout << "\n\n\n\t\t\t";
		}
		void OpenTheFile()
		{
			WRITE.open("File02.txt",ios::app);
		}
		void CloseTheFile()
		{
			WRITE.close();
		}
		void WriteToTheFile()
		{
			int k, m;
            cout << "\t\t\tHow many records you want : ";
			cin >> RecordsToWrite;
			for ( k = 0; k < RecordsToWrite; k++ )
			{
				PrepareTheFruits();
				cout << "\t\t\tGive me a fruit : ";
				cin >> Buffer;
				m = 0;
				while ( Buffer[m] != '\0' )
				{
					Fruits[m] = Buffer[m];
					m = m + 1;
				}
				WRITE << "\n" << Fruits;
			}
        }
        void ReadToTheScreen()
        {
            int k;
            for ( k = 0; k < RecordsToWrite; k++ )
            {
                cout << "\t\t\t\t" <<  Fruits << endl;
            }

        }
        void PrepareTheFruits()
		{
			int k;
			for ( k = 0; k < 11; k++)
			{
				Fruits[k] = 32; // 32 is the ascii code for SPACE
			}
			Fruits[10] = '\0';
		}

	private:
		char Fruits[11];
		char Buffer[50];
		int RecordsToWrite;
		ofstream WRITE;
};
Last edited on
Topic archived. No new replies allowed.