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

  • Home
  • SEARCH
  • 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 891527
In Process

The Archive Base Latest Questions

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

I have following code int wordLenght = 256, arrayLength = 2, i = 0,

  • 0

I have following code

 int wordLenght = 256, arrayLength = 2, i = 0, counter = 0;
 char **stringArray = NULL; 

 stringArray = calloc(arrayLength, sizeof(*stringArray));

 for(counter; counter<wordLenght; counter++) 
    stringArray[counter] = calloc(wordLenght, sizeof(stringArray));

 while(1)
 {
   printf("Input: ");
   fgets(stringArray[i], wordLenght, stdin);

   printf("stringArray[%d]: %s\n", i, stringArray[i]);

   if(i == arrayLength)
   {
     printf("Reallocation !!!\n");
     arrayLength *= 2;

     stringArray = realloc(stringArray, arrayLength*sizeof(*stringArray));

   } 

   i++;
 }    

I get this reallocation error:

*** glibc detected *** ./stringArray: realloc(): invalid next size: 0x0000000000b49010 ***
======= Backtrace: =========
/lib/libc.so.6(+0x775b6)[0x7f4dd12565b6]
/lib/libc.so.6(+0x7dd66)[0x7f4dd125cd66]
/lib/libc.so.6(realloc+0xf0)[0x7f4dd125d080]
./stringArray[0x4007f9]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7f4dd11fdc4d]
./stringArray[0x400629]

What’s my problem here ???

Thanks, greets

  • 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:54:21+00:00Added an answer on May 15, 2026 at 1:54 pm
     stringArray = calloc(arrayLength, sizeof(*stringArray));
    

    Here you probably wanted to use sizeof(char*)

    for(counter; counter<wordLenght; counter++) stringArray[counter] = calloc(wordLenght, sizeof(stringArray));
    

    Here you are looping 256 times (wordLenght) but you should only 2 times (arrayLength). Additionally you probably wanted to use sizeof(char) instead of sizeof(stringArray).

    if(i == arrayLength) {...}
    

    This check should be done before you call fgets, because right now you are firstly using memory and later allocate them.

    Additionally after you reallocate stringArray you need to allocate rest of strings using something like this

    for(counter = i; counter<arrayLength; counter++) stringArray[counter] = (char*)calloc(wordLenght, sizeof(char));
    

    And finally you need to free all allocated memory before you exit application.

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

Sidebar

Related Questions

i have the following code int arr[5]; printf(Input values:); for (i=0;i<5;i++) scanf(%d,&arr[i]); pthread_create(&thread1, NULL,
I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
I have the following code: int i=1; printf((i==1)? : hello); printf( hello); And I
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
I have the following code: int main(int argc, char** argv) { onelog a; std::cout
I have the following code : int *edges[500]; char arr[] = {'c','d'}; edges[0] =
Say we have the following code: int main(){ int a[3]={1,2,3}; printf( E: 0x%x\n, a);
Suppose you have the following code: int main(int argc, char** argv) { Foo f;
So...I have the following code: int main(void) { const char *s=hello, world; cout<<&s[7]<<endl; return
I have the following code: int get_int(void) { char input[10]; fgets(input, 10, stdin); //

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.