How to check if a string starts and ends with specific character in C

1 Answer

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

int main() {
    char str[] = "#c#"; 
     
    if (str[0] == '#' && str[strlen(str) - 1] == '#') {
        puts("yes");
    }
    else {
        puts("no");
    }
}


/*
run:

yes

*/

 



answered Apr 18, 2019 by avibootz

Related questions

...