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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:39:04+00:00 2026-05-15T13:39:04+00:00

I’m having troubles when calling a function taking a pointer to a string as

  • 0

I’m having troubles when calling a function taking a pointer to a string as a parameter. I need to get an Element’s name.

// method
void getStringFromCsv( char ** str );

Let me introduce the structures I’m working with (not written by me and part of a much bigger project, I can’t modify them).

// typedefs
typedef char      T_CHAR64[64];
typedef T_CHAR64  T_SYMBOL;

// generic element
typedef struct Element
{
  T_SYMBOL  name; 
} T_Element;

// csv element
typedef struct CsvElement
{
  Element * pElement;
  int   id;
} T_csvElement;

So, basically, I thought I would call the function like this :

T_Element * pData; // Not null, filled earlier
getStringFromCsv( &pData->pElement->name );

But this doesn’t work (warning: passing argument 1 of ‘STR_toCsv’ from incompatible pointer type). I’m using gcc with NetBeans 6.8.

I tried many things…

T_SYMBOL foo = "foo";
T_SYMBOL * pFoo = &foo;

getStringFromCsv( pDef->name, &pFoo ); // error : passing from incompatible pointer type

T_CHAR * pBar = &foo;      // error : init from incompatible pointer type
T_CHAR * pBaz = &(foo[0]); // OK

getStringFromCsv( pDef->name, &pBaz ); // OK

T_SYMBOL * pFooTest = &(foo[0]); // error : init from incompatible pointer type

…but ended up casting name to a char ** :

getStringFromCsv( (char**) &pData->pElement->name );

What is wrong with my code ?
Basically, SYMBOL = CHAR *, right ? Why is SYMBOL* != CHAR** ?
I’m pretty sure I’m missing something simple but right now… Nothing came.

EDIT
Here is getStringFromCsv :

void getStringFromCsv( char ** data )
{
  // pDesc is defined and not null
  csvDescriptorCat( pDesc, *data);
  csvDescriptorCat( pDesc, "\t");
}

void csvDescriptorCat( CsvDescriptor * pDesc, char* str)
{
  int len;
  if( str != NULL)
  {
    len = strlen(str);
    strcpy( &pDesc->line[pDesc->pos], str);
    pDesc->pos += len;
  }
}
  • 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-15T13:39:04+00:00Added an answer on May 15, 2026 at 1:39 pm

    If you wish to pass &pData->pElement->name to the function, the function must be declared as:

    void getStringFromCsv(T_SYMBOL * str);
    

    Alternatively you can use a temporary char * as Secure offered – but there’s not much point in doing this, because any updates to that char *‘s value can’t be used – the ->name member can’t be modified, as it’s an array.

    You might as well just declare the function as:

    void getStringFromCsv( char * str );
    

    …and call it as:

    getStringFromCsv( pData->pElement->name );
    

    (In this case, the function can still change the contents of the ->name array. What you can’t do is to change the position of the array itself).


    As well as Secure’s option, there’s another way if your compiler supports C99 compound literals:

    getStringFromCsv( &(char *){ pData->pElement->name } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I tested your code and it seems I got better… May 15, 2026 at 7:54 pm
  • Editorial Team
    Editorial Team added an answer For anyone that finds this thread later, if you are… May 15, 2026 at 7:54 pm
  • Editorial Team
    Editorial Team added an answer This is a problem I spend a fair amount of… May 15, 2026 at 7:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.