Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <iostream>
using namespace std;
int main()
{
	 char *STR[] = {"e", "es"};
	 char *SOL[] = {"e", "es"};
	 *SOL[0] = &STR[1];
}


Using the above code, I expect SOL's first valued index to obtain the memory address of STR's second index. I plan to do this to load bytes in from a file and compare them to another file for verification. This is necessary for emulation aspects, etc.
Posted

1 solution

Question is a bit unclear - what is the goal?
You have declared an array of pointers to character strings. As pointers and arrays have a lot in common in c++ there are a number of ways you can assign the string pointed to at index 1 in array 1 to index 0 in array 2. It can be done using either pointers or arrays.


C++
#include <iostream>
using namespace std;

int main()
{
	 char *STR[] = {"e0", "es0"};
	 char *SOL[] = {"e1", "es1"};

//#define ARRAY
#ifdef ARRAY
	 SOL[0] = STR[1];   // Treat as array
#else
	 *(SOL+0) = *(STR+1); // Treat as pointer.
#endif

	 cout << SOL[0] << endl; 
	 cout << SOL[1] << endl; 

 return 0;
 }
 
Share this answer
 
v5
Comments
nv3 23-Mar-14 7:11am    
Right to the point. +5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900