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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:05:09+00:00 2026-05-31T02:05:09+00:00

I am tried to implement next() PHP function in C. if I have The

  • 0

I am tried to implement next() PHP function in C. if I have

The different to my implementation is I want to do this work with more one points. For example:

if I have two char * like:

char * a = "ac\0";
char * b = "bd\0";

and I call:

printf("%c", cgetnext(a));
printf("%c", cgetnext(b));
printf("%c", cgetnext(a));
printf("%c", cgetnext(b));

gets an output like: abcd

but I get abab

here is my code:

`#include <string.h>
#include <stdlib.h>

typedef struct 
{
    int pLocation;
    int myindex;
    int lastIndex;
}   POINTERINFORMATION;

int                 __myIndex               = 0;
int                 pointersLocationsLength = 0;
char                * temparr               = NULL;
POINTERINFORMATION  pointersLocations[256];


int 
    plAdd (int p)
    {
        if (pointersLocationsLength >= sizeof(pointersLocations)) {
            return -1;
        } else {
            pointersLocations[pointersLocationsLength].pLocation = p;
            pointersLocations[pointersLocationsLength].lastIndex = 0;
            pointersLocationsLength ++;
            return pointersLocationsLength;
        }
    }

int 
    getPointer (int p, POINTERINFORMATION * out)
    {
        int i;
        for (i = 0; i < pointersLocationsLength; i++)
        {
            if(pointersLocations[pointersLocationsLength].pLocation == p)
            {
                pointersLocations[i].myindex = i;
                *out = pointersLocations[i];
                return 1;
            }
        }

        return 0;
    }

void 
    getPointerIndex(char ** variable, int * val)
    {
        char * buf = malloc(256);
        if(sprintf(buf,"%p", &variable) > 0){
            *val = strtol(buf, NULL, 16 );
        } else {
            *val = -1;
        }
    }

int 
    inArrayOfPointers (int pointer) 
    {
        POINTERINFORMATION pi;
        return getPointer(pointer, &pi);

    }

char 
    cgetnext(char * arr) 
    {
        char * myarr; 
        const size_t size = sizeof(char *) + 1;
        int pof;

        myarr = malloc(size);
        getPointerIndex (&arr, &pof);

        if (inArrayOfPointers(pof)){
            POINTERINFORMATION pi;

            if (getPointer(pof, &pi))
            {
                myarr = (char *)*(int *)pi.pLocation;
                __myIndex = pi.lastIndex;
                ++pointersLocations[pi.myindex].myindex;
            } else {
                return 0;
            }

        } else {

            if (plAdd(pof) == -1) {
                printf(" CANNOT ADD ELEMENT TO ARRAY\n");
                exit(0);
            } else {
                myarr = arr;
                __myIndex = 0;
            }
        }

        if (strlen(myarr) == __myIndex) {
            return 0;
        } else  {
            temparr = malloc(size);
            temparr = strdup(myarr);

            return myarr[__myIndex];
        }
    }`

how to fix this? differents solutions for solve it are very apreciated! Thanks 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-31T02:05:10+00:00Added an answer on May 31, 2026 at 2:05 am

    If you are specifically interested in char* “arrays”, then a simple solution might be to just increment the pointer. Note that if using dynamically allocated memory, you need to save the original pointer to free it. The same idea could be used for other data types as well.

    This is an example of what I mean. cgetnext here just returns the character at the current position in the array and increments pointer (that is passed by address).

    char cgetnext( char **p )
    {
       assert( p != NULL );
       // check for end of string
       if ( **p == '\0' )
          return '\0';
       return *(*p)++;
    }
    
    
    int main( int argc, char* argv[] )
    {
       char *a = "ac";
       char *b = "bd";
    
       printf( "%c", cgetnext(&a));
       printf( "%c", cgetnext(&b));
       printf( "%c", cgetnext(&a));
       printf( "%c", cgetnext(&b));
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery script I'm trying to implement om Magento and I've tried
I am trying to implement map function in VB.NET and I have tried the
I tried to implement __concat__ , but it didn't work >>> class lHolder(): ...
I once tried to implement Comet in PHP. Soon, I found that PHP is
I have been looking around for solutions, and tried to implement what is often
I have tried to implement doubly linked list in C++. Here is the code,
I have numerous index.php scripts using SEO-friendly arg format like example.com/path/to/index.php/opt/arg and would like
I want to resolve in Windsor a series of classes that implement this interface:
I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return
I tried to implement XOR swap in python. x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s

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.