Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-21-2005, 07:41 AM   #1 (permalink)
frier
Registered User
 
Join Date: Mar 2005
Posts: 4
frier is on a distinguished road
Array to pointer to pointer

Hi Guys,

Sitting with a problem.

I have a function, which demands a pointer to some data.

Code:
gputsym(x,0,(PGSYMBOL) &icon15);
icon15 is the pointer to the dataarea

When I write the pointername, I use in the dataarea, it works allright.

But the pointername should be substituted with a name entered in an array, but now it is going wrong.

I tried to declare my array like this

Code:
char mgtext[10][30], mgicon[10][6];
Actually the array mgicon should be an array[10] of strings but....
so instead, I manually read in from the file, each character at a time, and then add it to the mgicon[2][0] ... mgicon[2][6] (i,c,o,n,1,5,\0)

Now, mgicon[2] for example should contain 'icon15'

so the above code should be

Code:
gputsym(x,0,(PGSYMBOL) mgicon[2]);
This doesn't work, looked everywhere, can not find a solutions to this problem, hope somebody can give me a hint.

Best regards
Frier

Last edited by frier; 03-21-2005 at 07:45 AM. Reason: entering code-bracket
frier is offline   Reply With Quote
Old 03-21-2005, 08:56 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
(i,c,o,n,1,5,\0) = 7 characters not 6

So gputsym(x,0,(PGSYMBOL) mgicon[2]) recieves "icon15" without the '\0'
DJMaze is offline   Reply With Quote
Old 03-21-2005, 09:00 AM   #3 (permalink)
frier
Registered User
 
Join Date: Mar 2005
Posts: 4
frier is on a distinguished road
I've already did this , the variable contains the correct data, the problem is for gputsym to recognize the content of mgicon[] as a pointer.

Any suggestion?
frier is offline   Reply With Quote
Old 03-21-2005, 08:33 PM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
Code:
function gputsym(int x, int O, char *icon)
I think you should read your Dot Matrix LCD module Driver Library though (or isn't it for the lcd lib ?)
DJMaze is offline   Reply With Quote
Old 03-22-2005, 12:46 AM   #5 (permalink)
frier
Registered User
 
Join Date: Mar 2005
Posts: 4
frier is on a distinguished road
Yes, the function is for Ramtex library for graphical LCD.

I Have read the manual, and it state that it has to be a pointer to the data-area.

So the problem is to have the name of the pointer to the data-area in an array.

/Frier
frier is offline   Reply With Quote
Old 03-22-2005, 06:08 AM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
gputsym(x,0,(PGSYMBOL) mgicon[2])

what is PGSYMBOL for definition ?
In the above you say it's a char[6]

The info you gave is to limited for people who don't know what it is.
DJMaze is offline   Reply With Quote
Old 03-22-2005, 08:56 AM   #7 (permalink)
frier
Registered User
 
Join Date: Mar 2005
Posts: 4
frier is on a distinguished road
DJ!

I dont think what PGSYMBOL is matters in this case, the core of my question is:

How do I substitue a pointername with a name (equal to the pointer) in a variable (array), and get my function to treat the name as a pointer?

Maybe it is of importance, my c-skills is very limited at least when it comes to pointers. I have been programming all other languages for the last 20 years asm, pascal, vb etc. and this pointer-thing c/c++ is doing, is rather confusing and very opposite to e.g. pascal.

/Frier
frier is offline   Reply With Quote
Old 03-22-2005, 02:00 PM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
could this be of any interest ?
Or am i wrong here assuming you want pointers to functions in an array..
If you want to do the equivalent of something like:
Code:
Array $my_variables = { "item1", "item2", "item3"};
foreach ($item in $my_variables)
      exec($item);
Not specific any language here, but I think you'd get my guess, as to you're using strings to represent the variable names and uppon execution you want to access the variable values instead of the strings representing them..

It can't be done the way you are trying in C/C++
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-25-2005, 07:57 PM   #9 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
Quote:
Originally Posted by frier
How do I substitue a pointername with a name (equal to the pointer) in a variable (array), and get my function to treat the name as a pointer?
How do you write it in perl ?
"unsigned char *cpointer" is like "Pchar ppointer" in delphi/pascal
and pointer[0] equal to ppointer^

Because my english is limited so your text looks like the following to me:

PHP Code:
//void * is similar to Pointer in delphi/pascal
PGSYMBOL icon2;
void **array;
array = (
void**) malloc(10sizeof(void*));
array[
2] = (void*)icon2;
gputsym(x,0,(PGSYMBOL) array[2]);
free(array); 
But in my opinion it's better to have atleast some sort of struct so you may add/delete as many items as you want
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting an array of any Comparable objects plague Java 1 03-14-2005 07:24 PM
Different string types in C: char pointer, char array, etc. Sleep Standard C, C++ 0 01-23-2005 09:40 PM
Simple reverse programm silex Standard C, C++ 3 01-22-2005 09:03 AM
array pointer? Admin PHP 8 12-08-2003 04:51 PM
pointer to function with class? Kportertx Standard C, C++ 5 04-11-2003 06:12 AM


All times are GMT -8. The time now is 06:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting