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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:27:30+00:00 2026-06-02T18:27:30+00:00

I want to create a new array with the same size of chaine but

  • 0

I want to create a new array with the same size of “chaine” but only after the function

 char chaine[Lenght];   //Lenght = 20
 function(chaine, sizeof(chaine));

When I called “function” the size of “chaine” is changing randomly.

The new array “chaine2″ also needs to be full of ” * ” characters.

Let met try to explain with some printf :

     printf("chaine = %s\n", chaine);

will show on screen something like : chaine = WORDS (5 characters)

And i want “chaine2” to be shown like this : chaine2 = ***** (5 stars)

I apologize for my english, thank you for reading

  • 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-02T18:27:30+00:00Added an answer on June 2, 2026 at 6:27 pm

    Remember that char arrays are special, in the sense that they have a size, which you specify when you declare them, and a length, which depends on their contents. The size of an array is the amount of memory that’s been allocated to it. The length of a string is the number of characters before a terminating null ('\0').

    some_func() {
      int len = 20;      // Size of the array
      char chaine[len];  // Uninitialized array of size 20.
    
      memset(chaine, '\0', sizeof(chaine)); // Init to all null chars, len = 0
      strcpy(chaine, "WORDS"); // Copy a string, len = 5
    
      char *chaine2 = function(chaine, sizeof(chaine));
      printf("%s\n", chaine2);
      free (chaine2);
    }
    

    When you pass an array to a function, it’s treated like a pointer. So sizeof(str) inside the function will always return the size of pointer-to-char, and not the size of the original array. If you want to know how long the string is, make sure it’s null-terminated and use strlen() like this:

    char *function(char *str, int len) {
      // Assume str = "WORDS", len = 20.
      char *new_str = malloc(len); // Create a new string, size = 20
    
      memset(new_str, '\0', len);  // Initialize to nulls
      memset(new_str, '*', strlen(str)); // Copy 5 '*' chars, len = 5
    
      return new_str;  // Pointer to 20 bytes of memory: 5 '*' and 15 '\0'
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Java. I want to create Java Array and insert data into
I want to create a new project in Xcode (4.2), but I don't need
I want to create new WCF service and client. The 2 parties will communicate
I want to create new creative and check its audit status in facebook ads
I want to create new node of BeanTreeView, and when I add some node
I'm using SharePoint 2010. I want to create new view for my list. The
I want to create a new field (or two) in my table that is
I want to create a new custom control derived from ContentControl (it will be
I want to create a new WCF service and client. The 2 parties will
I want to create a new Rally user with the following C# code DynamicJsonObject

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.