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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:26:43+00:00 2026-05-15T20:26:43+00:00

I need to convert regexitem *regex to ctype variable, any ideas? C function expects

  • 0

I need to convert regexitem *regex to ctype variable, any ideas?

C function expects func(regexitem *regex)

    char *regex1Groups[] = { "a","b","x","s" ,NULL};
    char *regex2Groups[] = { "l" ,NULL};

    regexitem regex[] = {
            {"bla", regex1Groups,4 },
            {"bla2",regex2Groups,1 }
    };

First i defined

class regexitem(Structure): 
        _fields = ("regex",c_char_p), ("groups",c_char_p*size), ("groupsize",c_int)

and ran into first problem, declaring array of regexitem because size of groups is not known in advance.

  • 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-15T20:26:44+00:00Added an answer on May 15, 2026 at 8:26 pm

    Structs can only contain variable-length arrays at their ends, and on top of that when you assign an array variable to something you aren’t copying it, you’re assigning the memory location of the first element of the array. So I’m betting that your regexitem struct contains a pointer to the array of char pointers rather than containing the array of char pointers itself. If that’s the case, this might work:

    class regexItem(Structure):
        _fields_ = [("regex", c_char_p),
                    ("groups", POINTER(c_char_p)),
                    ("groupsize", c_int),
                    ]
    

    (You can keep the assignment to _fields_ as a tuple of tuples rather than a list of tuples if you want to.)

    Oh, for your regex groups, it’d be something like this:

    regex1Groups = (c_char_p * 5)("a", "b", "x", "s", None)
    regex2Groups = (c_char_p * 2)("l", None)
    

    And then your array of regexitems would be like so:

    regex = (regexItem * 2)(("bla", regex1Groups, 4),
                            ("bla2", regex2Groups, 1))
    

    Look through the ctypes documentation if you want to know more.

    http://docs.python.org/library/ctypes.html

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

Sidebar

Related Questions

I need to convert this date: 10.04.2011 19:00 To a date variable that I
I need to convert a (possibly) null terminated array of ascii bytes to a
I need to convert a Char to an Int in Haskell? For example: a
I need to convert a value which is in a DateTime variable into a
I need to convert a String to enum. I followed the idea in String
I need to convert a string vector in a simple string. I do not
I need to convert full state name to its official state address code. For
I need to convert a time difference (diff) between two actions into a human
I need to convert a Joda-Time DateTime into a String, in the following format:
I need to convert a column data into single row with multiple columns Example

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.