In my program I read in a text file an decrypt the text from an array. once decrypted i then have to do through it again and search for every tenth array member and show their memory location.

The code so far:

int main( )
int* pCrypted = NULL;
int crypted;	//holds the number of the ASCII value

	cout << "Enter filename: " << endl;		//ask user to enter desired file
	char filename[50];						//saves name of file
	ifstream myFile;			
	cin.get(filename, 50);					//retreives text from file;					//opens file

	if(!myFile.is_open())					//checks if file is open
		exit(EXIT_FAILURE);					//if cannot open then causes error
	string temp;
	char word[400];				//array for the the text
	myFile >> word;				//puts the text retrieved, into the array
	while(myFile.good())		//while loop to see if the file is still good
		myFile.get(word, 400);
		//cout << word;	//outputs the word to the command line
		//temp = temp + " " + word;
		//myFile >> word;			//puts next line retrieval into the array
	cout << "Received text is: " << word << "\n";				//outputs final line to command line	

	int shift = 0;		//array for the shifting
	char response;		//variable ready for users response

		//system("CLS");//clear screen
		decrypt(word);											//calls the decryption one the word array
		cout << "\nDecrypted text is: " << word << endl;		//outouts the decrypted text to the screen
		shift++;												//increments shift by one
		cout << "is this the correct state Y or N" << endl;		//asks user if the text is correctly decrypted
		cin >> response;	
	while(response != 'y');										//checks if users response was y for yes

	cout << "\nthe shift is: " << shift << endl;				//outputs the amount of shifts taken on to the screen
	///////////search array for every tenth memory location///////
	char d[400];
	pCrypted = &crypted;
	//search every tenth for pointer address
	for(int i=0; d[i] != 400; i+10) 
		d[i] = crypted;
		cout << "Memory Location is: " << pCrypted << endl;
		crypted = crypted + 10;					
	return 0;

What the program seems to do is find the first member and then just spam out that memory location for infinite times.

Recommended Answers

All 3 Replies

line 54: for(int i=0; d != 400; i+10)

The condition d[i] != 400 is never met. Probably should be i != 400 or better yet i < 400

And you mean



Thanks very much guys that's worked wonderfully. Can't believe it was something that little

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.