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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:09:57+00:00 2026-06-14T14:09:57+00:00

I have a function prototype which provides me with the result I’m after: #include

  • 0

I have a function prototype which provides me with the result I’m after:

#include <stdio.h>
#include <string.h>

int main ()
{
  char * pch;
  char str[] = " 81.243.230.174, 10.1.0.102";
  pch = (char*) memchr (str, ',', strlen(str));
  char * tch;
  memcpy (tch, str, pch-str);
  if (pch!=NULL){
    printf ("',' found at position %ld.\n", pch-str);
    printf ("XFF: %s\n", tch);
  } else {
    printf ("',' not found.\n");
  }
  return 0;
}

Returns the following:
$>’,’ found at position 15.
$>XFF: 81.243.230.174

I want to process the output of VRT_GetHdr from libvcl as str above, as follows:

char * pch;
char str[] = VRT_GetHdr(sp, HDR_REQ, "\023X-FF:");
pch = (char*) memchr (str, ',', strlen(str));
char * xff;
memcpy (xff, str, pch-str);

    if (get_country_code)
            VRT_SetHdr(sp, HDR_REQ, "\017X-Country-Code:", (*get_country_code)(xff), vrt_magic_string_end);

VRT_GetHdr returns a char pointer and the compiler complains about an “invalid initializer.”

If I change the assignment of
char str[]
to
char *str
, varnish dies at runtime (probably with a segfault).
How can I get the expected result from my inline C, without using the above pointer to array mess?

  • 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-14T14:09:58+00:00Added an answer on June 14, 2026 at 2:09 pm

    You can’t.

    The initializer expression must be literal to provide a compile-time size, and your function call isn’t.

    You might be able to get around this using C99’s automatic arrays, but it’s maybe easier and cleaner to just use a dynamically allocated array (using malloc(), or strdup() if you have it).

    Or even a static limit that is “large enough”, if you have reason to believe there is some limit to the length of the return value.

    Your code reads a bit like a re-implementation of strtok(), perhaps you can use it directly?

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

Sidebar

Related Questions

A have a function with a prototype of: void arryprnt(int[], string, int, string, string);
I have function in Javascript which works fine using prototype. The function is used
I currently have a partial-application function which looks like this: Function.prototype.curry = function() {
I have some (library API, so I can't change the function prototype) function which
Which Activator.CreateInstance overload function to call? I have a type returned from Type proxyType
I have the function prototype here: extern C void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to
suppose I have a function: function test(){} test.prototype.method01=function(){ //do something } test.prototype.method02=function(){ //how can
I have created one multiplication of complex function using prototype in java-script function ComplexNumber(real,imaginary)
I have a prototype representing a particual IFrame. That prototype have a function called
I have two functions here function Preloader() {} Preloader.prototype = { init:function() { //

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.