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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie in C - how to give offests in a CHAR names that overlap

Status
Not open for further replies.

ronofcarrollton

Programmer
Oct 24, 2005
2
US
Hi,
Newbie to C but long time programmer.
Example:
struct {
char [50] big_string;
char [30] smaller_string;
} struct_name;

*char in_between_string [10] = &struct_name.big_string [45];

The syntax may not be quite right but hopefully the intent is correct.

I would rather not use unions as it get quite messy.

The "in_between_string" defination above gets me an array of 10 pointers but I want a pointer that is char for a length of 10.

Then I can reference the offset size as being 10 characters and still use the "struct_name." to qualify it.

Thanks for any help

Ron
 
First of all, your struct would look like...
Code:
struct {
char big_string[50];
char smaller_string[30];
} struct_name;
When you're defining a pointer to an array of characters, there's nothing in the definition of the pointer to indicate the size of the array it's pointing to. The pointer [tt]in_between_string[/tt] would look like this...
Code:
char * in_betweek_string = struct_name.big_string[45];
This would make the pointer [tt]in_between_string[/tt] point to the 46th character position in the array [tt]big_string[/tt].

Hope this helps.
 
Thanks - I was just trying to carry the length where I could use "sizeof in a define to eliminate some keystrokes.

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top