if i had a string (Iamhere) stored in an array of characters, and i want to get just (amhere) in another array, is there a way of doing it?? I've been reading in the string functions but couldn't figure out how this is done?
but isn't strstr used when a string is already known, i'm trying to find a general case to start copying from the second element but it doesn't seem to be working i wrote this piece of code
/*get the required text after the operation*/
/*to copy everything after the first character*/
memcpy(text, mystring+1, length);
/*make last element is a null*/
printf("Substring is %s\n",text);
The code returns the substring but also returns garbage after it
where t was originally an array of 100 elements,
incompatible types in assignment
text=&t; ---> text is an array of chars and you are trying to use it as a pointer.
Furthermore you have to be carefully with trying to return pointers to variables created inside a function block, since as soon as the function is finished that variable doesn't exist anymore. i.e.char text will disappear when returntext() is finished.
strcpy(ftext,text); I am afraid that won't work neither. ftext is an uninitialized pointer, who knows to what is pointing to. Trying to change the content of what ftext points to will produce a segmentation fault.
Let me see if I can help you without divulging the actual code.
I believe you can benefit of looking at the function strcpy() as an example. Essentially, your customized function need to be prototyped the same way.
char *strcpy( char *s1, char *s2 );
strcpy accepts a pointer to a destination string and a pointer to a source string, both variables need to exist before you can pass it to strcpy; and only then it will do its work on them and return a pointer to the destination string, which still exist beforehand.
Hope that helps.