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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:30:43+00:00 2026-06-08T07:30:43+00:00

I am a newbie to C still, and I am having a problem with

  • 0

I am a newbie to C still, and I am having a problem with the memset function.

I pass a char * to a function, and inside this function I create an array, and then use memset to set each value. I have been using dbx to watch this variable as it enters the function, and for some reason it gets set to “” after we pass memset.

Firstly, why does this happen? I’m assuming that memset must be resetting the memory where the char * is located?

Secondly, is there a better way to set each element as “0”?

Here is my code:

static char *writeMyStr(char *myStr, int wCount) {

   // here myStr is set to "My String is populated"  

   char **myArr;
   myArr = (char **) malloc(sizeof(char *) * wCount);
   memset(myArr, 0, sizeof(char *) * wCount);   // myStr is set to ""

   ... populate array ... 

}
  • 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-08T07:30:45+00:00Added an answer on June 8, 2026 at 7:30 am

    Are you looking for zero the character, or zero the number? When initializing an array as so:

    memset(arr, 0, count);
    

    It is equivalent to

    memset(arr, '\0', count);
    

    Because 0=='\0'. The length of a string is the position of the first null terminator, so your string is zero-length, because the array backing it is filled with zeros. The reason people do this is so that as they add things to the string, they don’t need to re-null-terminate it.

    If you want your string to be “0000”… use the character zero:

    memset(arr, '0', count);
    

    But remember to null-terminate it:

    arr[count-1] = '\0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm realizing what a newbie I still am with this problem I have. I
I'm still newbie in SmartGWT, currently having a strange problem.. I am using Windows
I asked about this yesterday , but I'm still having problems. I wrote a
Greetings all, I'm an AJAX newbie, and I'm having a problem with same origin
Ok, this is about to drive me nuts. I'm still a newbie (and maybe
Java newbie here...caution! I've set this practice app up using this example as a
I am still newbie to android, please could someone help. I want to use
I'm still a newbie to rails. This is going to sound dart. I am
I'm an iPhone dev newbie, and I'm having a problem slightly similar to a
I'm still a newbie when it comes to javascript but I am having trouble

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.