How to delete first element in a string?

This is a discussion on How to delete first element in a string? within the C Programming forums, part of the General Programming Boards category; Hey guys, if you're given a string..what kind of function would you write to delete its first element in C. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Question How to delete first element in a string?

    Hey guys,
    if you're given a string..what kind of function would you write to delete its first element in C.
    Thanks

  2. #2
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up Try this Out

    Hi Try This code Out...

    void delfirstchar(char *str)
    {
    int i;
    char *st;
    str++;
    while(*str!='\0')
    {
    *st=*str;
    st++;
    str++;
    }
    *st='\0';
    str=st;
    }

    and lemme know if u have a problem.

    Initially you send the string into Str. then eliminating the first character, the others are entered into another string st. Finally you close st and then reassign st to str.
    Thats the whole idea.

    Regards
    Help everyone you can

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    49

    Re: Try this Out

    Or just with a loop:


    Code:
    for(i=0;i<strlen(string);i++)
             string[i]=string[i+1];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  2. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 11:47 AM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM

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