Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

With

Status
Not open for further replies.

DanJC

Programmer
Dec 6, 2001
19
0
0
SE
I am lazy!! I don't want to have to write out a struct's full name any time I want to reference one of it's members.

Is there a with statement (or equivalent) in C e.g.
Code:
struct mystruct
{
 int item1;
 char item2;
 float item3;
} struct1[20];

for(index = 0;index <20; index++)
{
with struct1[index]
{
  .item1 = 1;
  .item2 = &quot;m&quot;;
  .item2 = 4.35;
}
}

please can anyone help?

&quot;Arrgh *hack* *cough* damn pretzels!!!!...&quot;
 
nope... It is not like VB in that aspect. You have to write

struct mystruct
{
int item1;
char item2;
float item3;
} struct1[20];

for(index = 0;index <20; index++)
{

struct1[index].item1 = 1;
struct1[index].item2 = &quot;m&quot;;<-- uses 'm' instead
struct1[index].item2 = 4.35;

}

AND NOTE... to set item 2 to a single character you need single quotes... to set it to a string use double quotes but other things exist there that may be of use such as strcpy. If you do use strcpy or something along those lines you WILL need to allocate memory for item2.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top