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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to find the last occurrence of character in string with C

2 Answers

0 votes
#include <stdio.h> 
#include <string.h> 

int main(void)
{   
    char s[30] = "c c++ c# java python";
    char *p;
    
    p = strrchr(s, ' ');
    
    printf("%s", p);
     
    return 0;
}
  
        
/*
run:
     
 python

*/

 





answered Feb 24, 2017 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

int main(void) 
{
    char s[] = "c c++ c java";
    char ch = 'a';

    {
        char *last = strrchr(s, ch);
        if (last != NULL) 
        {
            printf("Last position is: %s\n", last);
            printf("Last position is: %ld\n", last - s);
        }
        else
        {
            printf("Not Found");
        }
    }
    
    return 0;
}
   
/*
run:

Last position is: a
Last position is: 11

*/

 





answered Aug 6, 2017 by avibootz

Related questions

...