Wednesday, 15 August 2012

c++ - Assigning a value to a variable from a structure -



c++ - Assigning a value to a variable from a structure -

i want assign value globally declared variable comes construction member.

here's code:

#include<iostream.h> #include<conio.h> #include<string.h> char question[15]; struct place{ char name[15]; int length; }aa={"paris",5}; void places() { question[15]=aa.name[15]; } main() { clrscr(); places(); cout<<question; getch(); homecoming 0; }

hope can help!

firstly - should stop using turbo c++, no longer supported, , antiquated implementation of c++. (you larn bad coding technique)

here place can download free modern compiler _and_ development environment in one..., here another.

regarding question: cannot utilize = operator create char array assignments have tried in places(). need become familer string functions. assignment making in void places() function, can utilize strcpy().

change:

question[15]=aa.name[15];//not correct. variables have been //created, not include array operator here `[]`

to:

strcpy(question, aa.name);

c++ arrays variables struct turboc++

No comments:

Post a Comment