How to print the characters from the start of a string that matches any character in another string in C

1 Answer

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

int main() {
    char s[] = "xyz c c++ c# 930 java python";

    for (int i = 0; i < strspn(s, "abcxyzdef"); i++) {
        printf("%c", s[i]);
    }

    return 0;
}



/*
run:

xyz

*/

 



answered Jan 5, 2021 by avibootz
...