C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2004, 01:21 PM
Srinivas Sagar Srinivas Sagar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 16 Srinivas Sagar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 0
Character array in C

I have a character array RIB which is a part of a structure REL

that is
typedef struct
{ char JUNK[17],
char RIB[3]
} REL


In my code I have an instance (maybe it is wrong to use that word in C but I come from a Java background)

REL rel;

Now I want to print the the first character of the character array RIB
so I try:

printf("First character in rib is :%c\n",&rel->RIB[0]);

But that does not print it out for me. I tried %s and and%d but to no avail ,any suggestions?

Reply With Quote
  #2  
Old January 16th, 2004, 01:36 PM
narbo narbo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 24 narbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
printf("First character in rib is :%c\n",rel.RIB[0]);

Reply With Quote
  #3  
Old January 17th, 2004, 06:34 PM
Bacat's Avatar
Bacat Bacat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Houston, TX
Posts: 161 Bacat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 12 m 50 sec
Reputation Power: 10
Send a message via MSN to Bacat
Your struct code should look like this, I believe:
Code:
struct REL {
char JUNK[17];
char RIB[3]
};

REL rel;      //defines a structure rel of type REL


So, rel is the name of a structure REL, and the char array RIB is referenced by rel.RIB[0], like narbo showed. If you created a pointer to the structure, then you would use -> notation...
Code:
struct REL *r;   //creates a pointer of type struct REL
r=&rel;      //points r to the address of structure rel
cout<<r->RIB[0];


Hope this helps you understand why it works that way!
-Tim

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Character array in C

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap