your problem is that you want to pass literal values to a sting after it has been initialised. normally its ok to to this:
Code:
char astring [20] = "Hello World"; //notice the quotes
but if you want to initiallise it later on, you'll have to do this:
Code:
char astring [20];
.
.
.
strcpy (astring, "Hello World");
Here's your code with the modifications, just one point of order first, when you declare struct:
that works on most compilers, but the ANSI standard, (to the best of my lecturers knowledge) is that you must use the struct keyword like so:
its just something you might run into on different systems. here is your original code with the modifications:
Code:
#include<iostream>
using namespace std;
struct membrs
{
int id;
int age;
char name[10];
char cmt[150];
};
int main()
{
membrs str;
membrs *ptr;
str.id=001;
str.age=21;
strcpy (str.name,"Guest");
strcpy (str.cmt, "who are you");
ptr=&str;
cout<<"welcome "<<ptr->name<<".\n";
cout<<"You are member number "<<ptr->id<<" and you are "<<ptr->age<<" years old\n";
cout<<"Your comment: "<<ptr->cmt<<"\n";
cin.get();
}