Normalize whitespace with strtok in C -



Normalize whitespace with strtok in C -

i trying utilize strtok normalize whitespace in string after have removed substring. when remove substring there 2 spaces between 2 words , want cut down 1, illustration deleting substring "rise and" string "the rising , fall of rome" leaves 2 spaces between , fall.

this have far have no experience strtok:

char *strdel(char *string, const char *substring) { int mainlen, sublen; // finds first occurrence of substring char *del_sub = strstr(string, substring); char *wspc, *df; while (del_sub != null) { // finds length of string origin of substring // found in main string mainlen = strlen(del_sub); // finds length of substring sublen = strlen(substring); // removes number of bytes needed after // first instance of substring memmove(del_sub, del_sub + sublen, strlen(del_sub)); wspc = strtok(string, " "); while ((df = strtok(null, " ")) != null) { strcat(string, df); memset(df, 0, strlen(df)); } // continues search occurrence of // substring until equals null del_sub = strstr(string, substring); } return(string); }

c whitespace strtok

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -