My goal:
- In the function
zad2()pass the arguments, which is an array of characters / string (char s[]). - In the function
zad2(char s[])I find the penultimate word in the line and after each of its letters I insert the symbol*. - Return processed
stomainfunction.
I have the following features:
Search for a space to highlight a word.
char* next_to_last(char* str) { char* end = &str[strlen(str)]; while (*end == ' ') end--; while (*end != ' ') end--; while (*end == ' ') end--; while (*end != ' ') end--; end++; return end; } Passage by word using the first function:
void zad2() { char buf[BUFSIZ]; while (printf("Введите строку для задания: ") && fgets(buf, 81, stdin) && *buf!='\n') { for(char* word = next_to_last(buf); !strchr(DELIM, *word); word++) { for (char* ptr = &word[strlen(word)]; ptr>word; ptr--) { *(ptr+1) = *ptr; } *++word = '*'; } puts(buf); } } The essence of the problem is that I need not to enter the string through fgets() , as in the second function, but immediately work with the transmitted s and return it to main .
void zad2(char s[], char buf[]) {. Everything. - PinkTuxsin which there is text. I need to pass it to thezad2()function for processing. FrombufI just need to get rid of myself and make all changes ins. - A_lina19spassed to the function as a normal parameter:void zad2(char *s)orvoid zad2(char s[]). You arenext_to_last()argument tonext_to_last()(we will not talk about its strangeness), what’s the problem with doing the same thing? - PinkTux