In the GetInput function the line of code name = "John";
will not assign the string literal "john" into an array (unless you are initializing a declaration of a char array).
the '=' is for assignment of values.
you can use the c style string library for string manipulation:
# include <string.h>
and use the strcpy function in the following formats strcpy(string 1,string 2);, strcpy(string 1,"string literal");
the function copies the contents of string 2 to string 1;
Sample code:
# include <iostream.h>
# include <string.h> //C-style string library
void main()
{
// Variable definition
char string1[50]="something";
char string2[50]="nothing";
strcpy(string1,string2);
cout<<string1<<endl;
strcpy(string2,"New String");
cout<<string2<<endl;
return;
}
OUTPUT 1: nothing
OUTPUT 2: New string.
Mike
|