Write a C Program for extracting only operators from a large string.
#include <stdio.h>
int contains(char target, char *operators, int n) {
int contains = 0;
for (int i = 0; i < n; i++)
if (target == operators[i]) contains = 1;
return contains;
}
int main() {
char largeString[1024]
char operators[4] {'+', '-', '*', '/'};
for (int i = 0; i < 1024; i++) {
if (contains(largeString[i], operators, 4)) {
printf("%c at position %d\n", largeString[i], i);
}
}
}
Comments
Leave a comment