Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:18:17+00:00 2026-05-28T08:18:17+00:00

This problem is driving me crazy, I’m sure I’m missing something. I need to

  • 0

This problem is driving me crazy, I’m sure I’m missing something. I need to initialize an array of chars using only pointers. Below is the code I have so far:

    int p2(){
         /* Implements problem 2 of lab */

         // Create an array 
         char **s = (char**)malloc( 11 *sizeof(char));
         char *p = *s;
         char start ='A';

         while( p != s+10){
            *p = start;
            start++;
            p++;
         }

         return(0);
    }

The problem I’m having is I don’t know how to address the characters inside of the array. I understand the base address of the array is **s, and the pointer to the first element is *s. What I don’t understand is how to get to **s+10 (i.e. the end of the array).

Can anyone shine some light for me??? Please!

EDIT: Ok, looks like I misunderstood the question. I appears I need to create an array of strings (thus the char ** allocation). Then I need to loop through this array, and assign each string (i.e. char *) a value 15 chars long. Please let me know if I’m understanding this correctly:

char **strings ==> strings[0 … n ] where each element is a pointer to a char (possibly an array). There for *string ==> strings[0], *(string+1) = strings[1], etc etc.

Am I close or way off?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:18:18+00:00Added an answer on May 28, 2026 at 8:18 am

    char **s is 2 dimensional array of characters, or array of C strings if you want.
    If you want to use array of characters you should use:

    char *string = (char*)malloc( 11 *sizeof(char));
    

    If you really want to initialize array of strings, at first step you’re initializing array of pointers, that’s:

    char **s = (char**)malloc( 11 *sizeof(char *));
    

    Please note that I’m using char * inside sizeof. Than when you may use strings, but at first you must initialize each string.

    s[0] = (char*) malloc( 15*size(char)); // This is actually string, 14 characters long (NULL terminated)
    char *p = s[0]; // p is pointer to beginning of your string now
    

    And there’s two way how to address your string:

    s[0][3] // 4th character of your string
    p[3]
    

    Or if you want to use just pointers:

    char *p = *(s+0);
    *(p+3); // 4th character
    *((*(s+0))+3) // To do it "hardcore"
    

    EDIT: added an example

    When you have **char p and use p++ or p + 1, C increases memory address. *p operator tells compiler that you now want to work with data stored in memory, not with pointer. Therefor those two syntax do the same:

    p[10] = 'a';
    *(p+10) = 'a';
    

    So if you want traverse both your dimensions, you should use:

    for( int i = 0; i < 11; i++){
        char *p = *(s+i);
        for( int j = 0; j < 10; j++){
            *(p + j) = 'a'; // Say you wanna fill them with as
        }
    
        // You may also use this syntax:
        while( p < (*(s+i) + 10)){ // or use != instead of <
            *p = 'a';
            p++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is driving me crazy because I am not sure why this just
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning
This problem is driving me a bit crazy. The code seems to be segmentation
This is driving me crazy, I just can't find out the problem: I have
OK, this is driving me crazy: First example, no problem: <script> window.myvar = 150;
This is driving me crazy. Very grateful if someone could help me out! Problem:
I'm using .Net 2.0 and this is driving me crazy but there's probably some
This problem has been driving me crazy and Monday mornings don't really help. I'm
I'm wondering if this is something somewhat simple, but I'm having a problem ONLY
This is driving me crazy. Can anyone tell me what I am missing here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.