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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:09:36+00:00 2026-06-10T10:09:36+00:00

int size_of_daten = 5; char *data[size_of_daten]; char *normal_Pointer = (char*)malloc(sizeof(char) * 100); int i;

  • 0
int size_of_daten = 5;
char *data[size_of_daten];
char *normal_Pointer = (char*)malloc(sizeof(char) * 100);
int i;

for(i=0; i<size_of_daten; i++) {
    data[i] = (char*)malloc(sizeof(char) * 100);
}

data[0] = "0";
data[1] = "1";
data[2] = "2";
data[3] = "3";
data[4] = "4";

printf("data[2] %s\n",data[2]);

strcpy(normal_Pointer,data[2]);

for(i=0; i<size_of_daten; i++) {
   free(data[i]);
}

free(data);

I just tried this… even I freed the array as I malloced it… also I copied the value of data[2] and didn’t point at it… so that shouldn’t be the problem…

  • 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-10T10:09:38+00:00Added an answer on June 10, 2026 at 10:09 am

    You’re trying to copy the strings "0", "1", etc. into your data array: you can’t just use = to copy strings, you’ll need to use a string library method like strcpy.

    Once you assign to your array elements those literal strings, e.g.: data[0]= "0";
    , the array elements no longer point to the memory that you’ve allocated, they point to memory that doesn’t belong to you, and you can’t use free. You’ve lost the references to your memory blocks from malloc, causing a memory leak.

    Furthermore, you can’t do free(data); because it wasn’t allocated using malloc: it’s an array allocated on the stack.

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

Sidebar

Related Questions

Could somebody tell me the difference between: int *p; p=(int*)malloc(10*sizeof(int)); free(p); or int *p;
I have tried this: #define format(f, ...) \ int size = strlen(f) + (sizeof((int[]){__VA_ARGS__})/sizeof(int))
int main(void) { int* p = (int*) malloc(sizeof(int)); int* q = (int*) malloc(sizeof(int)); *p
Is this list-initialization of an array of unknown size valid in C++0x? int main()
What does sizeof (int) * p semantically mean? Is it: 1. sizeof( (int) *p
Is the sizeof(enum) == sizeof(int), always ? Or is it compiler dependent? Is it
I create a 2D dynamic array: a = (int**)calloc(n-1, sizeof(int)); for(i = 0; i
Fixed. include main() { int n; int i; char tempMonth[255]; //Used to store the
I have a table of the form CREATE TABLE data { pk INT PRIMARY
I have a file with data in this format: Name WeekDay Month day, Year

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.