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 205 views
1 answer 137 views
1 answer 135 views
1 answer 159 views
1 answer 119 views
2 answers 233 views
1 answer 201 views
...