Thread: memset

  1. #1
    Registered User
    Join Date
    Feb 2018
    Posts
    24

    memset

    Code:
    #include <stdio.h>
    #include <string.h>
    
    void main (){
    
        char str[50];
        
    
        memset(str,'#',50);
            printf("%s",str);
    
    }
    this prints all ## these stuffs but also prints some junk value to end ? can anybody tell me why ?

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I believe if you think about it you'll find that you haven't terminated the string; recall that in C a string is an array of characters terminated by the nul ('\0') character.

    How many '#' characters can you fit in your array (char str[50]) remembering that you have to leave room for the final '\0' character?

  3. #3
    Registered User
    Join Date
    Feb 2018
    Posts
    24
    Quote Originally Posted by Hodor View Post
    I believe if you think about it you'll find that you haven't terminated the string; recall that in C a string is an array of characters terminated by the nul ('\0') character.

    How many '#' characters can you fit in your array (char str[50]) remembering that you have to leave room for the final '\0' character?
    thanks for your attention i handled my mistake

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memset
    By DickArmy in forum C Programming
    Replies: 3
    Last Post: 06-30-2009, 04:59 PM
  2. how to use memset for int?
    By manav in forum C Programming
    Replies: 4
    Last Post: 04-12-2008, 07:15 AM
  3. memset() function
    By sureshN in forum C Programming
    Replies: 1
    Last Post: 05-25-2007, 05:42 AM
  4. memset
    By l2u in forum C Programming
    Replies: 3
    Last Post: 07-03-2006, 04:16 PM
  5. memset()
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 08-11-2002, 09:34 PM

Tags for this Thread