×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Thanks Lim, need a little more info PLEASE

 Forum Search FAQs Links MVPs

Thanks Lim, need a little more info PLEASE

(OP)
Thanks fo your help Lim
I picked up some good tips
I was as you suspected trying to create an array
holding 20 names *name[21]

I am just learning about pointers and was 'trying' to use pointers to manipulate the input and output

also I tried to crate an array names[21][30]
and set a pointer for ir ie *n_ptr = names but I got an error

I am not familiar with malloc
is there a way of doing what I was trying to do just using pointers?

Thanks again

RE: Thanks Lim, need a little more info PLEASE

Ok:
char name[21][30] = {"Jim",.....,"Gander"};//21 all together
char (*n_ptr)[30] = name; // this is a pointer to array of char[30]
This will work. And you can do n_ptr+1 to acces next name.
The different:
name [21][30] is an array. It is already allocated and size of this array can not be changed and you can not free it. This array can store 21 names and each name can not be longer then 29 (don't forget that each string is terminated by '/0').
(*n_ptr)[30] is just a pointer. There is no room to store any values you have to allocate space by malloc like this:
n_ptr = malloc (21 * sizeof (char[30]); to allocate room for 21 names 29 lengh each and don't forget to free this memory when you don't need this.
Or you can put ptr to already allocated array (seefirst lines);

You better start with reading some book this will save you a lot of time. Don't be afraid to spend more to understand what is the pointer in C without it you will not be able to program.

Try to find the difference between:
char *name[30];
and
char (*name)[30];

Good luck.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.