Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int ch_str(char* str, char ch);
- int words_counter(char* str);
- int longest_word(char* str);
- void print_words(char* str);
- char* reverse_words(char* str);
- int main(){
- char ch='A';
- //char str[10]={'A','b','2','4','f','5','g'};
- char str[] = "bomonka yea eee";
- printf("%d\n",words_count(str));
- return 0;
- }
- int ch_str(char* str, char ch)
- {
- int i = 0;
- while (str[i])
- {
- if (str[i] == ch)
- {
- return i;
- }
- else i++;
- }
- return -1;
- }
- int words_counter(char* str)
- {
- int i = 0, counter = 0, word = 0;
- char sep[] = " !?123456789,.&";
- while (str[i])
- {
- if ( ch_str(sep, str[i]) != -1 )
- {
- if (word)
- {
- counter++;
- word = 0;
- }
- }
- else
- {
- word = 1;
- }
- i++;
- }
- if (word) counter++;
- return counter;
- }
- int longest_word(char* str){
- int i=0;
- int current_len=0;
- int max_len=0;
- int counter,word = 0;
- char* sep = {'"','.',','};
- while(str[i]){
- if( ch_str(sep,str[i])!= -1){
- if (word){
- if(current_len>max_len)
- max_len=current_len;
- counter=0;
- word=0;
- }
- else {
- word=1;
- }
- i++;
- }
- if(word && current_len>max_len)
- max_len=current_len;
- return max_len;
- }
- }
- void print_words(char* str){
- int i=0;
- int counter = 0;
- int word=0;
- char* sep = {'"','.',','};
- while(str[i]){
- if( ch_str(sep,str[i])!= -1){
- if (word){
- purchar('\n');
- word=0;
- }
- else {
- word=1;
- putchar(str[i]);
- }
- i++;
- }
- }
- }
- char* reverse_words(char* str)
- {
- int i = 0, word = 0, start = 0;
- char sep[] = "123456789./";
- while (str[i])
- {
- if (ch_str(sep, str[i]) != -1)
- {
- if (word)
- {
- reverse_substr(str, start, i - 1);
- word = 0;
- }
- }
- else
- {
- if (!word)
- start = i;
- word = 1;
- }
- i++;
- }
- if (word)
- {
- reverse_substr(str, start, i - 1);
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement