Writing an array of integers into notepad (or some other word processor).

I'm a very novice programmer and I've been trying to create a simple program to "encrypt" a message. I'd like to fill an array with integer values and create a text document of those numbers. Ideally that could then be sent and put into a reverse algorithm to decode the message. I've got everything except the sending the values to the text document but I haven't been able to find a solution to that last part.
(Sorry about the bad variable names and awful program format)

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
#include<iostream>
#include<cmath>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<fstream>
using namespace std;
int main()
{
	string message, password, place=" ";
	char letter=' ';
	int i=0, mNumber, pNumber, a, pLength=0, numb;
	cout<<"What is your message?"<<endl;
	getline(cin, message);
	cout<<"What is the password?"<<endl;
	getline (cin, password);
	a=message.length();
	int arr[a];
	ofstream myfile;
	myfile.open("encryptionfile");
	while (pLength< password.length())
	{
 	 pNumber=int(password[pLength]);
	 while(i<message.length())
	 {
	 	mNumber=int(message[i]);
	 	numb=mNumber+pNumber;
	 	//cout<<"numb  "<<numb<<endl;
	 	arr[i]=numb;
	 	cout<<arr[i]<<endl;
	 	myfile<<arr[i]<<" ";
	 	pLength=pLength+1;
	 	i=i+1;
	 }
	 if(pLength=password.length())
	 	{
	 		pLength=0;
		 }
	}
	myfile.close();
}
Last edited on
The encryptionfile that you create is a "text document". Plain ASCII text, no format.

Change the filename into "encryptionfile.txt" and the desktop GUI will magically believe that it is text.
1
2
  a=message.length();
  int arr[a];

Variable length arrays (VLA) are not allowed in C++. Better use a std::vector.
Topic archived. No new replies allowed.