String and NULL

This is a discussion on String and NULL within the C Programming forums, part of the General Programming Boards category; How do u store make a string with letters to null ? strcpy(word, 0) ? Also also do u detect ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    16

    String and NULL

    How do u store make a string with letters to null ? strcpy(word, 0) ?

    Also also do u detect if the string is null?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >How do u store make a string with letters to null ?
    Code:
    word[0] = '\0';
    >Also also do u detect if the string is null?
    Code:
    if ( word[0] == '\0' )
      ...
    My best code is written with the delete key.

  3. #3
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I was thinking of something like this
    Code:
    #include <string.h>
    */..../*
    memcpy(string, 0, sizeof string);
    But I guess your way works if you don't need to ensure everything in the array is null, I always over complicate things.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    memset(mystring, '\0', sizeof(mystring));

  5. #5
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    Quote Originally Posted by chrismiceli
    I was thinking of something like this
    Code:
    #include <string.h>
    */..../*
    memcpy(string, 0, sizeof string);
    But I guess your way works if you don't need to ensure everything in the array is null, I always over complicate things.
    err, what if string is defined as follows
    Code:
    char *string="Hello World";
    The one who says it cannot be done should never interrupt the one who is doing it.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >err, what if string is defined as follows
    Then any attempt to modify it results in undefined behavior.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21