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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -