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,884 questions

51,810 answers

573 users

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

2 Answers

0 votes
#include <stdio.h> 
#include <string.h> 
#include <stdbool.h> 
  
bool IsUpper(char ch);
void GetUppercaseFirstLetterWords(char *s, char *UppercaseFirstLetterWords);
  
int main(void) {   
    char str[] = "C C++ c# Java php";
    char UppercaseFirstLetterWords[30] = "";
      
    GetUppercaseFirstLetterWords(str, UppercaseFirstLetterWords);
      
    puts(UppercaseFirstLetterWords);
      
    return 0;
}
  
void GetUppercaseFirstLetterWords(char *s, char *UppercaseFirstLetterWords) {
    char *p;
     
    p = strtok (s, " ");
    while (p != NULL) {
        if (IsUpper(p[0])) {
            strcat(strcat(UppercaseFirstLetterWords, p), " ");
        }
             
        p = strtok (NULL, " ");
    }
} 

bool IsUpper(char ch) {
    if (ch >= 'A' && ch <= 'Z')
        return true;
       
    return false;
}
 
 
 
        
/*
run:
     
C C++ Java
    
*/

 



answered Feb 3, 2017 by avibootz
edited Jan 4, 2024 by avibootz
0 votes
#include <stdio.h>
#include <ctype.h>
#include <string.h>
   
void extract_only_words_with_first_letter_upperrcase(char s[], char words[]) {
    char *token;
    char *delimiter = " ";
   
    token = strtok(s, delimiter);
    while (token != NULL) {
        if (isupper(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_upperrcase(s, words);
   
    printf("%s\n", words);
   
    return 0;
}
   
   
   
   
    
/*
run:
      
C General-purpose Computer Language 
    
*/

 



answered Apr 13, 2024 by avibootz
...