Форум » C/C++ для начинающих (C/C++ for beginners) » C Programming,removing individual characters from a string updated » Ответить

C Programming,removing individual characters from a string updated

lordcideon: My problem states: "Write a function that deletes all occurrences of a character from a string. The function should take two arguments: the string name and the character to be removed. For example, if 'message' contains the string 'HappyHolidays', the function call 'delete(message, 'H') should place the string 'appyolidays' into 'message'. Test your function by calling it from main() after first inputting a test string and a character to remove from the user. After the function returns, output the resulting string length and the string. -any help would be great :)-

Ответов - 1 новых

Сыроежка: The function can be defined the following way [pre2] char * remove( char *s, char c ) { char *q = s; while ( *q && *q != c ) ++q; char *p = q; while ( *q ) { if ( *++q != c ) *p++ = *q; } return s; } [/pre2]



полная версия страницы