more on strings

This is a discussion on more on strings within the Linux Programming forums, part of the Platform Specific Boards category; okay... say I have a string. char *str; str="Hello"; I want to remove a certain character completely from it, on ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    44

    more on strings

    okay... say I have a string.

    char *str;

    str="Hello";

    I want to remove a certain character completely from it, on a certain spot. for example, str[0] would equal H. perhaps if str[0] equals H I want to remove str[0] comepletey. making the value, "ello". any help? thanks.
    [Strut]

    I lay on my bed watching the stars, and I thought to myself... Where the hell is my roof?

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    If you want to remove the first one.

    Code:
    #include <string.h> 
    #include <stdio.h> 
    int main() 
    { 
          char *str = "hello"; 
          str++;
          puts( str ); 
          return 0;
    }
    If you want to modify what str points to then write
    char str[] = "Hello";

    This will most likely crash on linux as str is allowed to be
    stored in constant data section:
    Code:
    #include <string.h> 
    #include <stdio.h> 
    int main() 
    { 
         char *str = "hello"; 
          str[3] = 'A';    
          str++;
          puts( str ); 
          return 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    44
    thakns guys, for your help. I really appreciate it.
    [Strut]

    I lay on my bed watching the stars, and I thought to myself... Where the hell is my roof?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

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