Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
03-04-2005, 02:29 PM
#1
Member
Registered: Dec 2003
Location: Canada
Distribution: Suse 10
Posts: 206
Rep:
number of element in a array of pointer?
hi
under linux, c language
Code:
char *fname[]={"/A_L1_HLD_YEL_NOR_Run_Counter.txt", "/A_L1_HLD_GRN_NOR_Run_Counter.txt", "/A_L2_HLD_GRN_NOR_Run_Counter.txt", "/B_L1_HLD_YEL_NOR_Run_Counter.txt", "/B_L1_HLD_GRN_NOR_Run_Counter.txt", "/B_L2_HLD_GRN_NOR_Run_Counter.txt", "/C_L1_HLD_YEL_NOR_Run_Counter.txt", "/C_L1_HLD_GRN_NOR_Run_Counter.txt", "/C_L2_HLD_GRN_NOR_Run_Counter.txt" };
int i;
for(i=0; i < SIZEOFFNAME;i++){
for each element in fname (SIZEOFFNAME)... i would like to do something...
how to get the number of elment for fname?
03-04-2005, 02:38 PM
#2
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,782
Rep:
what do you mean by element? fname is just an array of pointers with 9 entries(pointers).
03-04-2005, 02:47 PM
#3
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
You can do it like argv works. Just end the entires with a NULL:
Code:
{
char *strings[] = { "foo", "bar", "baz", NULL };
int i;
for(i = 0;strings[i];++i)
puts(strings[i]);
}
03-04-2005, 02:47 PM
#4
Member
Registered: Dec 2003
Location: Canada
Distribution: Suse 10
Posts: 206
Original Poster
Rep:
Quote:
Originally posted by perfect_circle
what do you mean by element? fname is just an array of pointers with 9 entries(pointers).
in my for loop, i would like to go on the 1 entries, after second entries...
i don't know if *fname[i] is ok?
are there any place we could post c program and people comment it?
i would like to improve a c program, but i'm not a c expert
03-04-2005, 02:53 PM
#5
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,782
Rep:
I think itsme86 already answered you that. An array of pointers is just an array.
03-08-2005, 08:35 PM
#6
Member
Registered: Mar 2005
Location: College station, Texas
Distribution: UBUNTU 10.04
Posts: 61
Rep:
try this:
int i=0,count=0;
while(*fname[i]!=NULL)
{
count++;
i++;
}
03-08-2005, 09:21 PM
#7
Moderator
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502
Rep:
Quote:
Originally posted by aditya1
try this:
int i=0,count=0;
while(*fname[i]!=NULL)
{
count++;
i++;
}
Why not just?
Code:
int count=0;
while(fname[count])
count++;
03-09-2005, 11:50 AM
#8
Member
Registered: Mar 2005
Location: College station, Texas
Distribution: UBUNTU 10.04
Posts: 61
Rep:
thanks for ur suggestion
Thread Tools
Search 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
HTML code is Off
All times are GMT -5. The time now is 02:39 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News