Hey Guys. Im having a hard time figuring this out. I realize there are a bunch of topics out there discussing this problem but I couldn't find anything that was helpful to this particular situation.
#include <iostream>
#include <string.h>
using namespace std;
typedef char charType[4];
int main()
{
char a[2] = {'a','b'};
charType MyChar;
for(int i=0;i<3;i++)
{
MyChar = a[i];//i want to set the value of MyChar to whatever a[i] has at that moment in the loop.
strcpy(MyChar,a[i]); //this doesnt work either.
/*MyFunction(MyChar)<--- this function takes in MyChar suppose..*/
}
return 0;
}
Its giving me the errors:
prog.cpp: In function ‘int main()’:
prog.cpp:15: error: incompatible types in assignment of ‘char’ to ‘char [4]’
prog.cpp:16: error: invalid conversion from ‘char’ to ‘const char*’
prog.cpp:16: error: initializing argument 2 of ‘char* strcpy(char*, const char*)’
My goal is to somehow copy the elements of the array to MyChar to use it later. Any suggestions would be much appreciated. Thanks.