I'm getting "Invalid Initializer", what am I doing wrong?
Because you can't initialise like that, you need a constant expression as the initialisation value. Replace it with:
int main (void) {
char testStr[50] = "Hello, world!";
char revS[50]; strcpy (revS, testStr);
// more code here
}
Or, if you really want initialisation, you can use something like:
#define HWSTR "Hello, world!"
int main (void) {
char testStr[50] = HWSTR;
char revS[50] = HWSTR;
// more code here
}
This provides a constant expression with minimal duplication in your source.
Arrays arent assignable.
You should use memcpy to copy contents from testStr
to revS
memcpy(revS,testStr,50);
Only constant expressions can be used to initialize arrays, as in your initialization of testStr
.
You're trying to initialize revS
with another array variable, which is not a constant expression. If you want to copy the contents of the first string into the second, you'll need to use strcpy
.