954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

finding the memory location of every tenth array member's memory location

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
	myFile.open(filename);					//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
	
	

	do
	{
		//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.

LateNightCoder
Newbie Poster
10 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

And you mean

for([...];i+=10)


.

Caligulaminus
Junior Poster
106 posts since Feb 2011
Reputation Points: 72
Solved Threads: 30
 

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

LateNightCoder
Newbie Poster
10 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: