LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 03-04-2005, 02:29 PM   #1
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Rep: Reputation: 30
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?
 
Old 03-04-2005, 02:38 PM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
what do you mean by element? fname is just an array of pointers with 9 entries(pointers).
 
Old 03-04-2005, 02:47 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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]);
}
 
Old 03-04-2005, 02:47 PM   #4
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Original Poster
Rep: Reputation: 30
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
 
Old 03-04-2005, 02:53 PM   #5
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
I think itsme86 already answered you that. An array of pointers is just an array.
 
Old 03-08-2005, 08:35 PM   #6
aditya1
Member
 
Registered: Mar 2005
Location: College station, Texas
Distribution: UBUNTU 10.04
Posts: 61

Rep: Reputation: 15
try this:
int i=0,count=0;
while(*fname[i]!=NULL)
{
count++;
i++;
}
 
Old 03-08-2005, 09:21 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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++;
 
Old 03-09-2005, 11:50 AM   #8
aditya1
Member
 
Registered: Mar 2005
Location: College station, Texas
Distribution: UBUNTU 10.04
Posts: 61

Rep: Reputation: 15
thanks for ur suggestion
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
index of an element in the array ? thelonius Programming 1 09-24-2005 12:41 PM
about array and pointer seeLnd Programming 5 05-30-2004 07:56 AM
return index of element in java multidimensional array dave bean Programming 8 11-28-2003 11:00 AM
pointer to a 2D array dhanakom Programming 7 09-07-2003 04:22 AM
C++ Six Element Array petercool Programming 2 08-20-2003 11:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration