Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define STRING "Hello, Ara! I am glad to see you, my friend! How are you doooing? Goood!"
- int qtyWordsInStr(char *str);
- void InWord3_O(char *str);
- void InWord3_Syll(char *str);
- void streamWords(char *str);
- void polyndromWords(char *str);
- void superWordsPrint(char *str);
- void main() {
- int n = strlen(STRING) + 1;
- char *str = malloc(sizeof(char) * n);
- strcpy(str, STRING);
- printf("There are %d words in String\n", qtyWordsInStr(str));
- InWord3_O(str);
- InWord3_Syll(str);
- streamWords(str); printf("%s\n",str);
- polyndromWords(str);
- superWordsPrint(str);
- free(str);
- }
- int qtyWordsInStr(char *str){
- int qtyWords=0;
- int ukLetter=0;
- int i=0;
- do{
- if (str[i]<91 && str[i]>64 || str[i]>96 && str[i]<123){
- ukLetter=1; i++; continue;
- }
- if (ukLetter==1){
- qtyWords++; ukLetter=0;
- }
- i++;
- } while(str[i]);
- return qtyWords;
- }
- void InWord3_O(char *str){
- int i=0;
- int ukEnd=0;
- int ukO=0;
- int ukLetter=0;
- do{
- if (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123){
- if (str[ukEnd]=='o'||str[ukEnd]=='O') ukO++;
- ukLetter=1; ukEnd++; continue;
- }
- if (ukLetter==1 && ukO==3){
- for (; str[i], i<ukEnd; i++) printf("%c",str[i]);
- printf(" ");
- }
- ukEnd++; i=ukEnd; ukLetter=0; ukO=0;
- } while(str[i]);
- printf("\n");
- }
- void InWord3_Syll(char *str){
- int i=0;
- int ukSyl=0;
- int ukEnd=0;
- char *vowels="euioaEUIOA";
- do{
- if (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123){
- int t,ukVow=0;
- for (t=0; vowels[t]; t++)
- if (str[ukEnd]==vowels[t]){
- ukVow=1;
- break;
- }
- if (ukVow==1) ukSyl++;
- ukEnd++; continue;
- }
- if (ukSyl==3){
- for (; str[i], i<ukEnd; i++) printf("%c",str[i]);
- printf(" ");
- }
- ukEnd++; i=ukEnd; ukSyl=0;
- } while(str[i]);
- printf("\n");
- }
- void streamWords(char *str){
- int i,k,t,uk=0;
- int qtyWords=0;
- int maxLong=0;
- int wordLong=0;
- for (i=0; str[i]; i++){
- if (str[i]<91 && str[i]>64 || str[i]>96 && str[i]<123){
- uk=1;
- wordLong++;
- }
- else{
- if (uk==1){
- qtyWords++;
- if (wordLong>maxLong) maxLong=wordLong;
- uk=0; wordLong = 0;
- }
- }
- }
- maxLong++;
- char wordsArr[qtyWords][maxLong];
- char *pointer_to_char = str;
- uk = 0;
- int num_of_incorrect_chars;
- for (i = 0; i < qtyWords; i++) {
- wordLong = 0;
- while (str[uk] < 91 && str[uk] > 64 || str[uk] > 96 && str[uk] < 123){
- if (str[uk] < 91 && str[uk] > 64) str[uk]+=32;
- uk++;
- wordLong++;
- }
- memcpy(&wordsArr[i][0], pointer_to_char, sizeof(char)*wordLong);
- num_of_incorrect_chars = 0;
- while (str[uk] != '\0' && !(str[uk] < 91 && str[uk]>64 || str[uk] > 96 && str[uk] < 123)){
- uk++;
- num_of_incorrect_chars++;
- }
- pointer_to_char += (num_of_incorrect_chars + wordLong);
- wordsArr[i][wordLong]='\0';
- }
- for (i=0; i<qtyWords; i++)
- for (k=0; k<qtyWords-i-1; k++)
- if (strcmp(wordsArr[k],wordsArr[k+1])>0){
- for (t=0; t<maxLong; t++){
- char c=wordsArr[k][t];
- wordsArr[k][t]=wordsArr[k+1][t];
- wordsArr[k+1][t]=c;
- }
- }
- uk=-1;
- for (i=0; i<qtyWords;i++){
- for(k=0; wordsArr[i][k]; k++){
- uk++;
- str[uk]=wordsArr[i][k];
- }
- uk++;
- str[uk]=' ';
- }
- str[uk+1]='\0';
- }
- void polyndromWords(char *str){
- int i,k;
- int havePol=0;
- for (i=0; str[i]; i++){
- int wordLong=0;
- int uk=i;
- int ukPol=1;
- while (str[uk] < 91 && str[uk]>64 || str[uk] > 96 && str[uk] < 123){
- wordLong++;
- uk++;
- }
- for (uk=0; uk<=wordLong/2; uk++)
- if (str[i+uk]!=str[i+wordLong-uk-1] && str[i+uk]-32!=str[i+wordLong-uk-1]
- && str[i+uk]!=str[i+wordLong-uk-1]-32){
- ukPol=0;
- break;
- }
- if (ukPol==1){
- for (uk=0; uk<wordLong; uk++, i++) printf("%c",str[i]);
- printf(" ");
- havePol=1;
- }
- else i+=wordLong;
- }
- if (havePol==0) printf("No polyndrom words");
- printf("\n");
- }
- void superWordsPrint(char *str){
- int i;
- for (i=0; str[i]; i++){
- int qtyLetters=0;
- int ukEnd=i;
- while (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123) ukEnd++;
- int wordLong=ukEnd-i;
- int k,t;
- for (k=0; k<wordLong; k++){
- for (t=i; t<ukEnd; t++) printf("%c",str[t]);
- printf(" ");
- }
- i=ukEnd;
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement