Answer to Question #274680 in C for Lucky

Question #274680

Write a C Program for extracting only operators from a large string.

1
Expert's answer
2021-12-04T10:18:41-0500
#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);
  }
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS