PDA

View Full Version : C++ Programming, strings


codexmax
10-22-2009, 07:30 AM
I have been looking at this for so long and can't figure out whats wring with it. Any help would be much appreciated!! Assume all the necessary header files are included.

char *s2 = "Peter Piper";
char *s4[]= { "c++", "is", "peachy" };



//I'm a bit confused at this point if this will compile and if so what is the //output. If not, what is the problem.

strcpy(s2, s4[1]); // it will copy "is" into s2 and it will work and compile,
cout << s2 << endl; //output is "is" But this is read only data... so not sure



for(int i =0; i < 3; i++) // i'm not sure what this would do...
cout << s4[i] [0] << endl;

Millenia
10-22-2009, 09:06 AM
I'm a bit confused at this point if this will compile and if so what is the //output. If not, what is the problem.I presume you haven't compiled it yet, and as you say want to know the output?


Program has been terminated receiving signal 11 (Segmentation fault)
With 4 warnings:

warning: deprecated conversion from string constant to ‘char*’Or do you want to know what the error means? I presume you have imported the string.h header?