1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

handle character at string(c)

Discussion in 'C' started by oror84, Jan 24, 2011.

  1. oror84

    oror84 New Member

    Joined:
    Jan 15, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    i wanted to know if there is any way to read character`s from string one by one,
    and set it in other string.
    i mean
    i have this string:

    char *get = "hello";

    now i want to get over the string char by char and if the letter != 'l' copy it to other string, like :
    Code:
    char *copy;
    char c; int i;
    for (i=0;get[i] != '\0';i++)
    c = get[i];
    if (c != 'l')
    {
       copy[j] = get[i];
        j++;
    }
    
    i dont want to do it by strchr,strtok... i want do it by reading char by char from the string,
    (the all problem when i tring to add the char to the copy array it tells me :
    canot covert char to char *
    any idea?
    Thanks,
    Or.
     
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    In the above snippet *copy is a pointer to a character that you have never initialized. You will need to initialize this variable before you can use it. You will need to insure that it large enough to hold the results of your copy.

    Jim
     

Share This Page