I am searching for a specific word in a sentence and check for it using strstr(). Then check the return of it to see if it returns NULL to continue onward. Finally, check to see if first char is a "space" and if so, change it to "9". MY question is, from what is returned (the base address of the substring of that sentence and what was after it), how can I copy that to another string to use it.
So far...
Code:
char *ptr, *ptr_str;
char *segment[5];
/* Omit code for ease. */
ptr = strstr(string, segment[i]);
if(ptr != NULL){
printf("---> Residual part of the string was %s\n", ptr);
ptr_str = malloc(sizeof(ptr) + 1);
strcpy(ptr_str, ptr);
printf("Returned from first successful strstr call is: %s.\n",
ptr_str);
/* See if their is an space present in the present wx group and
truncate/remove it if necessary. */
if(ptr_str[0] == " ") ptr_str[0] = "9"; /* Assign the first character to a random in -- "9"; */
I get compile error:
array_search_strstr.c:warning: comparison between pointer and integer
array_search_strstr.c:warning: assignment makes integer from pointer without a cast
Confusing as it prints out the residual part in the print statement...
Any idea?