Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,989 questions

51,934 answers

573 users

How to extract only words with first-letter lowercase from a string in C

5 Answers

0 votes
#include <stdio.h> 
#include <string.h> 
#include <stdbool.h> 
    
bool IsLower(char ch);
void GetLowercaseFirstLetterWords(char *s, char *words);
    
int main(void)
{   
    char s[] = "C C++ c# Java php Rust go";
    char words[256] = "";
        
    GetLowercaseFirstLetterWords(s, words);
        
    puts(words);
        
    return 0;
}
  
void GetLowercaseFirstLetterWords(char *s, char *words) {
    char *p;
       
    p = strtok (s, " ");
    while (p != NULL) {
        if (IsLower(p[0])) {
            strcat(strcat(words, p), " ");
        }
               
        p = strtok (NULL, " ");
    }
} 
  
bool IsLower(char ch) {
    if (ch >= 'a' && ch <= 'z')
        return true;
         
    return false;
}
       
       
       
          
/*
run:
       
c# php go
      
*/

 



answered Feb 3, 2017 by avibootz
edited Apr 13, 2024 by avibootz
0 votes
#include <stdio.h>
#include <ctype.h>
#include <string.h>
  
void extract_only_words_with_first_letter_lowercase(char s[], char words[]) {
    char *token;
    char *delimiter = " ";
  
    token = strtok(s, delimiter);
    while (token != NULL) {
        if (islower(token[0])) {
            strcat(words, token);
            strcat(words, " ");
        }
        token = strtok(NULL, delimiter);
    }
}
  
int main() {
    char s[] = "C is a General-purpose Computer pRogramming language";
    char words[256] = "";
  
    extract_only_words_with_first_letter_lowercase(s, words);
  
    printf("%s\n", words);
  
    return 0;
}
   
  
  
  
   
/*
run:
     
is a pRogramming language 
   
*/

 



answered Apr 13, 2024 by avibootz
0 votes
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
void print_only_words_with_first_letter_lowercase(char s[]) {
    char *token;
    char *delimiter = " ";
 
    token = strtok(s, delimiter);
    while (token != NULL) {
        if (islower(token[0])) {
            printf("%s\n", token);
        }
        token = strtok(NULL, delimiter);
    }
}
 
int main() {
    char s[] = "C is a General-purpose Computer pRogramming language";

    print_only_words_with_first_letter_lowercase(s);
 
    return 0;
}
 
 
 
 
  
/*
run:
    
is
a
pRogramming
language
  
*/

 



answered Apr 13, 2024 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
#include <ctype.h>

// Function to extract and print words starting with lowercase
void print_lowercase_words(char *text) {
    char *word = strtok(text, " ");
    
    while (word != NULL) {
        if (islower((unsigned char)word[0])) {
            printf("%s ", word);
        }
        word = strtok(NULL, " ");
    }
}

int main() {
    char text[] = "PHP rust JavaScript c C++ java Typescript python";

    print_lowercase_words(text);

    return 0;
}



/*
run:

rust c java python

*/

 



answered Jan 16 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

// Function that returns an array of lowercase words
char** get_lowercase_words(char *text, int *count) {
    char *copy = strdup(text);  // duplicate because strtok modifies the string
    char *word = strtok(copy, " ");
    
    char **result = NULL;
    int size = 0;

    while (word != NULL) {
        if (islower((unsigned char)word[0])) {
            result = realloc(result, (size + 1) * sizeof(char*));
            result[size] = strdup(word);  // store a copy of the word
            size++;
        }
        word = strtok(NULL, " ");
    }

    *count = size;
    free(copy);
    
    return result;
}

int main() {
    char text[] = "PHP rust JavaScript c C++ java Typescript python";

    int count = 0;
    char **words = get_lowercase_words(text, &count);

    for (int i = 0; i < count; i++) {
        printf("%s ", words[i]);
        free(words[i]);  // free each word
    }

    free(words);  // free the array

    return 0;
}



/*
run:

rust c java python 

*/

 



answered Jan 16 by avibootz

Related questions

...