How do I read a fraction into C to do math with it? (The fraction will contain the slash symbol) For example, A user will input 3/12. (a string) The program will find the gc
This uses sscanf to get the numbers, you can use scanf directly of course:
#include int main() { const char *s = " 13/6 \n"; int a,b; sscanf(s, "%d/%d", &a, &b); printf("%d frac %d\n", a, b); return 0; }