Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 598

Counting frequency of char using switches

$
0
0

I am trying to count the amount of time each char appears in a string, I'm using switches and a for loop, however, they are not being incremented properly. Here is my code

let countChar x =   match x with'A' -> countA := !countA + 1;  | 'C' -> countC := !countC + 1;  | 'T' -> countT := !countT + 1;  | 'G' -> countG := !countG + 1;   ;;let demoStri = "ACGTACGT" in for j = 0 to 7 do  countChar demoStri.[j];  let tempA = !countA in  print_int tempA;  print_string "\n";  let tempC = !countC in  print_int tempC;  print_string "\n";  let tempG = !countG in  print_int tempG;  print_string "\n";  let tempT = !countT in   print_int tempT;  print_string "\n";done

But for some reason it's only incrementing 1, and it returns 1 0 0 0, 2 0 0 0, 3 0 0 0 and so on..... I was wondering if something went wrong in the process?


Viewing all articles
Browse latest Browse all 598

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>