473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Printf, array of structures and pointers...

Hi,

I have a pointer *pos, an array of structure "valid_param_s[]" and a
member name.

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s[*pos].name);

This code doesn't work, so I want to know how make it work :-).
I could create another temporary variable to store *pos and do :
(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s[variable].name);

But I would do it without temporary variable, if it's possible ;).

--
--
ThE_TemPLaR
Nov 13 '05 #1
7 5838
Eddahbi Karim wrote:
Hi,

I have a pointer *pos, an array of structure "valid_param_s[]" and a
member name.

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s[*pos].name);


Assuming pos is pointing to the array element that you want to print,
the last line should be:

,pos->name);

Nov 13 '05 #2
On Fri, 17 Oct 2003 09:16:41 GMT
"T.M. Sommers" <tm**@mail.ptd.net> wrote:

Assuming pos is pointing to the array element that you want to print,
the last line should be:

,pos->name);


pos is the position in the array.

Maybe http://nopaste.php-q.net/17283 would help you ?
Line 153 ;)

(I prefer to paste a link, because there's no need to flood here :))

--
--
ThE_TemPLaR
Nov 13 '05 #3
Eddahbi Karim wrote:
Hi,

I have a pointer *pos, an array of structure "valid_param_s[]" and a
member name.

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s[*pos].name);

This code doesn't work, so I want to know how make it work :-).
I could create another temporary variable to store *pos and do :
(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s[variable].name);

But I would do it without temporary variable, if it's possible ;).


If pos is a pointer to a particular member of your valid_param_s[]
array, then just access the member directly through the pointer:

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,pos->name);

An array subscript (that is inside the []'s) must be an integer
expression - you can't use the pointer like that.

Nov 13 '05 #4
On Fri, 17 Oct 2003 10:28:22 +0100
Thes <no*@ctually.myaddress.com> wrote:

If pos is a pointer to a particular member of your valid_param_s[]
array, then just access the member directly through the pointer:

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,pos->name);

An array subscript (that is inside the []'s) must be an integer
expression - you can't use the pointer like that.


Ok, So I'll do without pointers ;)

Thank you.
--
--
ThE_TemPLaR
Nov 13 '05 #5


Eddahbi Karim wrote:
On Fri, 17 Oct 2003 10:28:22 +0100
Thes <no*@ctually.myaddress.com> wrote:
If pos is a pointer to a particular member of your valid_param_s[]
array, then just access the member directly through the pointer:

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,pos->name);

An array subscript (that is inside the []'s) must be an integer
expression - you can't use the pointer like that.
Ok, So I'll do without pointers ;)


No need. The code segment you posted was fine, it just wasn't clear that
*pos was an integer.

I looked at your code posting at http://nopaste.php-q.net/17283 and the
line you say is a problem does not match the code you posted in your
article. The code at line 153 on your web page DOES have a problem. It is:

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,valid_params_s.name);
^NOTE!

i.e. it's missing the index ([*pos]) to valid_params_s.

Ed.
Thank you.


Nov 13 '05 #6
Eddahbi Karim wrote:
On Fri, 17 Oct 2003 10:28:22 +0100
Thes <no*@ctually.myaddress.com> wrote:
If pos is a pointer to a particular member of your valid_param_s[]
array, then just access the member directly through the pointer:

(void) fprintf(stderr, "Invalid parameter %s\n"
"Type --help for more "
"informations\n"
,pos->name);

An array subscript (that is inside the []'s) must be an integer
expression - you can't use the pointer like that.

Ok, So I'll do without pointers ;)


For us to find out what is wrong with your code, we need to see a
definition of all the involved elements. In particular, we do not have a
definition of struct parameters. You don't tell us what exactly your
problem is either (does not compiler ? gives you a warning ? crashes at
runtime ? demons flying out of your nose ? random cities blasted to
smitherens ?). Be more specific and we should be able to help you...

Were you tired of your co-nationals that you prefered c.l.c to f.c.l.c :-) ?

--
Bertrand Mollinier Toublet
int main(){char*strchr();int j=1234;char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.\n",*i="iqgbgxmbbla.llsvoaz:zdxylaxejivnidhd @ttopnjeftuh-i";while
(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}

Nov 13 '05 #7
On Fri, 17 Oct 2003 08:05:51 -0700
Bertrand Mollinier Toublet
<be*****************************@enst-bretagne.fr> wrote:


For us to find out what is wrong with your code, we need to see a
definition of all the involved elements. In particular, we do not have
a definition of struct parameters. You don't tell us what exactly your

problem is either (does not compiler ? gives you a warning ? crashes
at runtime ? demons flying out of your nose ? random cities blasted to

smitherens ?). Be more specific and we should be able to help you...

Ok ok, I'll do it next time :)
Were you tired of your co-nationals that you prefered c.l.c to f.c.l.c
:-) ?


Not really :-D
--
--
ThE_TemPLaR
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: michi | last post by:
Hello everybody, I have following problem: I have an array of pointers to structures: table* tab = new table; and structure table is like this: struct table{ CSLL::node* chain;
3
by: michi | last post by:
Hello, I need to initialize a 2 dimensional square arrays of structures. The size of array I get from the user. I can do one-dimensional array, but I don't know how to specify the size of array...
8
by: Frank Münnich | last post by:
Hi there.. My name is Frank Münnich. I've got a question about pointers that refer to an array of a structure. How do I declare that type? If I have declared a structure struct mystruc {...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
7
by: Frank M. | last post by:
I'm trying to declare an array of pointers to structures so that I can make the last element a NULL pointer. I figure that it would more easily allow my library routines to know when to stop...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
7
by: Kathy Tran | last post by:
Hi, Could you please help me how to declare an araay of pointer in C#. In my program I declared an structure public struct SEventQ { public uint uiUserData; public uint uiEvent; public uint...
15
by: Paminu | last post by:
Still having a few problems with malloc and pointers. I have made a struct. Now I would like to make a pointer an array with 4 pointers to this struct. #include <stdlib.h> #include <stdio.h>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.