Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   handle character at string(c) (http://www.go4expert.com/forums/handle-character-string-c-t24713/)

oror84 24Jan2011 17:41

handle character at string(c)
 
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.

jimblumberg 24Jan2011 19:24

Re: handle character at string(c)
 
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


All times are GMT +5.5. The time now is 04:10.