LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-30-2014, 06:40 PM   #1
errigour
Member
 
Registered: May 2009
Posts: 366

Rep: Reputation: 6
Pointer to an array of arrays


How do you point to an array of arrays? I want to point to array[0] and increment a ptr to use *ptr to compare the letters of array[0].

Code:
int main(int argc, char *argv[])
{
     char *array[] =
     {
          "Array one.\0",
          "Array two.\0",
          "Array three.\0"
     };

     char *ptr = array[0];

     while ( *ptr != '\0' )
     {
          printf("%c", *ptr);
          ptr++;
     }
     printf("\n");
}
Ok nevermind I just tested that and it works. Just ignore this.

Last edited by errigour; 05-30-2014 at 06:47 PM.
 
Old 05-31-2014, 04:40 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
FYI, you have an array of pointers, not an array of arrays. Also, the "\0" is redundant in string literals (unless you want 2 nul characters).
 
  


Reply



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
[SOLVED] expressing arrays in mixed pointer and array format atlantis43 Programming 2 10-10-2013 11:40 PM
warning while compiling a program with pointer arrays etc jamesbon Programming 10 12-26-2010 11:09 PM
libpng Uninitialised Pointer Arrays Vulnerability win32sux Linux - Security 1 03-03-2009 05:44 PM
Pointer Arrays JMJ_coder Programming 16 11-15-2007 04:01 PM
using arrays and functions and trying to initialize a point in the array mshinska Programming 1 11-11-2005 02:21 AM

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

All times are GMT -5. The time now is 03:50 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