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 6139917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:03:06+00:00 2026-05-23T18:03:06+00:00

I am trying to pass a character pointer array as an input from C

  • 0

I am trying to pass a character pointer array as an input from C test driver to C++ function (available in C wrapper)

char* LowerList[10];
LowerList[0]="abc";
LowerList[1]="def";
LowerList[2]="hij";

When available on the C++ side the values displayed for the the element is displayed as

char* LowerList[0]="abc";
LowerList[1]="def";
LowerList[2]="hij";
LowerList[3]=ƒì¶S<\$ UV<35?Ä@
LowerList[34]=ƒ<bad pointer>

I need to get the size of the array passed on to the C++ size which I could have got using
while (LowerList[count]) but unable to do so because of the junk value.
Please let me know if any way I can find the correct size of the char* LowerList[] by initialising ,memory allocation or converting it to vector.

Corrected the above code for typo error

Here are my comments on some of the suggestions given to me so far:

1) Pass the size of the array as a parameter as well- A limitation for my scenario .2) Conversion to the vector need the size to be available 3) Sentinel value at which position I need to add . As stated earlier I am trying to handle a scenario where the user pass the value as 3 which leads to the failure.I don’t have any control on restricting the way C user my C++ wrapper with his C test driver.

  • 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-23T18:03:06+00:00Added an answer on May 23, 2026 at 6:03 pm

    The pointers LowerList[3] through LowerList[9] are all uninitialized, if I’m not mistaken. You could always just use NULL as a sentinel value, and either assign it explicitly or do something like this:

    char* LowerList[10] = { "abc", "def", "hij" };
    

    This should initialize the remaining pointers in the array to NULL.


    In response to your second comment:

    #define LOWER_LIST_SIZE 10
    #define MINIMUM_SIZE 2
    
    #if LOWER_LIST_SIZE < MINIMUM_SIZE
        #error "LOWER_LIST_SIZE must be >= MINIMUM_SIZE"
    #endif
    
    char *LowerList[LOWER_LIST_SIZE] = // etc.
    

    Or something like that.

    http://en.wikipedia.org/wiki/C_preprocessor#User-defined_compilation_errors_and_warnings

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass an array of character arrays to a C function using
I'm trying I have a string that I pass into my function from user
I am trying to pass an array of character strings (C style strings) to
im trying to pass two parameters to a function, i being an int value
I am trying to pass a member function within a class to a function
I'm trying to convert a char to Character before it gets pushed on a
I have a JNI function that returns a UChar array (from the ICU4C library)
I'm trying to pass an keydown event from one textbox to another. What I
I am trying to create a function that will pass some parameters to a
I am trying to read input and pass it only if it is a

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.