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 307 views
1 answer 216 views
1 answer 228 views
1 answer 245 views
1 answer 194 views
...