How to check if two specific characters exists in a string with C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(int argc, char **argv) 
{
    char s[] = "c programming"; 
     
    if (strchr(s, 'p') && strrchr(s, 'c'))
        printf("Exist\n");
    else
        printf("Not Exist\n");
     
    return 0;
}
  

    
/*
run:
  
Exist
  
*/

 



answered Jan 10, 2020 by avibootz

Related questions

1 answer 200 views
1 answer 127 views
1 answer 124 views
1 answer 145 views
1 answer 112 views
2 answers 228 views
1 answer 192 views
...