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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:27:47+00:00 2026-06-11T15:27:47+00:00

I’m trying to read int and strings arrays in MATLAB of the following function:

  • 0

I’m trying to read int and strings arrays in MATLAB of the following function:

int DLLEXPORT getdata(int *index, char *id[])

In C I just do the following code and it works:

int count;       
int *index = calloc(MAXLINE, sizeof(int));
char **id = calloc(MAXLINE, sizeof(char*));

for (for i = 0; i < MAXLINE; ++i)                      
       id[i] = malloc(MAXID);

errcode = getdata(index, id);

In MATLAB I’m trying the following code with no luck:

errorcode = libpointer('int32');
index = libpointer('int32Ptr');
id = libpointer('stringPtrPtr');

[errorcode, index, id] = calllib('mylib','getdata', index, id);

I’ve already tried to initialize the libpointers and I got the same message “Segmentation violation detected”. Someone could help me?

  • 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-06-11T15:27:48+00:00Added an answer on June 11, 2026 at 3:27 pm

    You definitely need to initialize your pointers – right now they point to nowhere, they are initialized to 0. This most likely causes the segfault. If you have tried to initialize them, you must have done it wrong. Try sth. like this

    index = libpointer('int32Ptr', [1 2 3 4]);
    id = libpointer('stringPtrPtr', {'asdfasdf', 'asdfasdf'});
    

    You can also pass normal matlab arrays instead of making a libpointer:

    [errorcode, index, id] = calllib('mylib','getdata', [1 2 3 4], {'asdfasdf', 'asdfasdf'});
    

    You can find information about matlab types and the corresponding native types here.

    Edit Here is a simple shared library function that takes your input (your comments below) and prints one string on the screen using mexPrintf

    #include <string.h>
    #include <mex.h>
    void testfun(int *index, char* id[]){
      int idx0  = index[0];
      mexPrintf("printing string %d: id[0] %s\n", idx0, id[idx0]);
    }
    

    The function uses the first value from integer array (index[0] in your case) to print the specified string from an array of strings (id[index[0]]). The output is

    printing string 0: id[0] 01234567890123456789012345678901
    

    So it works, try it. Remember you must also provide the corresponding header file to loadlibrary!

    If you can execute the above correctly, most likely the data you supply to getdata is wrong and you must be getting a segfault somewhere there. Maybe you modify the input parameters in some way? e.g. create non-NULL terminated strings?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.