GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Apr-2005, 16:07
kai85 kai85 is offline
...is NOT a boy!
 
Join Date: Jan 2005
Posts: 58
kai85 is on a distinguished road

array of pointers to ......


I want to declare an array of pointers to arrays of characters.and then I want the user to enter these pointers , is such a thing possible?
Well ive written a test program which asks the user to enter 2 pointers(a or b)
in any order he\she wants , then the program is supposed to go and print the array that
each pointer points to!
Here’s the code(I don’t get any errors but it simply doesn’t execute):
CPP / C++ / C Code:
#include<iostream.h>
void f(char *,int);
int main(){

	char array[4]={'a','r','e','\0'};
	char arrayq[4]={'z','i','z','\0'};


	char *a=&array[0];
	char *b=&arrayq[0];;
	char *s[2];//this is my array of pointers, that the user initializes.

	cout<<"enter ur pointers(a or b)"<<endl;
	
	for(int i=0;i<2;i++){
	cin>>s[i]>>endl;// i think this line has some major problems that i ..!!!
	f(s[i],4);//call to the f function so that it prints the arrays the pointers     
	           //are pointing to
}
	
return 0;
}

void f(char *a,int size){
	for(int i=0;i<size;i++){
		cout<<*a<<'\t';
	a++;
	}
	cout<<endl;
}

well?
  #2  
Old 18-Apr-2005, 17:06
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,621
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by kai85
I want to declare an array of pointers to arrays of characters.and then I want the user to enter these pointers , is such a thing possible?


well?

Pointers are memory addresses, and access to memory is controlled by the program and/or operating system, not the user. So it is not, in general, possible for users to give values to pointers that can be used to access arbitrary memory locations.

Note also that pointer values that you can print out using standard C library I/O routines are "virtual memory" addresses, not actual physical memory addresses. If you know that a given virtual address is valid for your program (by printing out the value of a pointer to a variable in your program), then you can assign that value to a pointer and you can access that memory location. But I must emphasize: that memory address is relative to the starting address of a block of memory that was given to your program at the time the program was loaded for execution, and there is no way that a user program can know the physical memory location associated with the pointer value within the program.

In fact, for hosted environments with modern operating systems such as Windows XP or Linux, user programs can not directly access any physical resources (memory addresses, I/O controller port address, video RAM, etc.) There may be specific API (Applications Programming Interface) functions designed so that Debugger programs can get to the low-level hardware. Or there may be shared library routines that can be linked into programs to allow access to physical resources under some defined interface specification.


For embedded systems and other "real mode" programs running without memory-managed operating systems, it is possible in a C program to specify memory addresses, I/O addresses, etc. directly and access the resources through pointers with the given values.

Regards,

Dave
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 18:35
template comiling problems - need expert debugger! crq CPP / C++ Forum 1 01-Feb-2005 21:26
array of pointers to strings mirizar CPP / C++ Forum 5 21-Jan-2005 10:24
Function and Array (w/ reference variables) question brookeville CPP / C++ Forum 15 07-Dec-2004 01:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:51.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.