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
Keep a pointer to the head of the string.
Then look into using strchr() to get a second pointer that points to the / character.
You can then:
char [] or char * — that's your numerator as a C string./0 nul terminator at the end of the string. Store those characters in a second char [] or char * — that's your denominator as a C string.Use atoi() to convert both C strings to integers.
If strchr() returns NULL, then you can do error checking very easily because there was no / in the input string.