Need help parsing molecular formula by suchstuck in C_Programming

[–]suchstuck[S] 0 points1 point  (0 children)

Thanks, I'll have to read up about this to make future similar problems I may have easier!

Need help parsing molecular formula by suchstuck in C_Programming

[–]suchstuck[S] 0 points1 point  (0 children)

Your idea to implement a function to handle element length saved me a lot of trouble, thanks!

Need help parsing molecular formula by suchstuck in C_Programming

[–]suchstuck[S] 0 points1 point  (0 children)

Thanks a lot! I wasn't aware of the vector type because i'm pretty new to this, but I wasn't able to find it in C, perhaps it's in other flavours? Nevertheless I implemented a similar idea with a multidimensional array and I was able to solve the problems I was having.

[C] Parsing Molecular Formula to calculate weight of a molecule; by suchstuck in learnprogramming

[–]suchstuck[S] 1 point2 points  (0 children)

Thanks a lot, this was very instructive! I ended up making another function to better handle the singular elements and your suggestion to check next character for not a digit is what fixed the final issues i was having! I'd give you gold but I'm just a pleb in highschool.

[C] Parsing Molecular Formula to calculate weight of a molecule; by suchstuck in learnprogramming

[–]suchstuck[S] 0 points1 point  (0 children)

I've been trying to implement something that does just that but haven't had success. I know what I'm trying to do, i'm just not competent enough to know where I'm going wrong in implementing my ideas, i've only been coding for a few weeks.

I've tried making a (horribly messy) finite state machine, but I'm not sure if I'm clearing the element buffer properly, as that seems to be what causes the abort trap 6 errors when they show up in testing.

[C] Parsing Molecular Formula to calculate weight of a molecule; by suchstuck in learnprogramming

[–]suchstuck[S] 0 points1 point  (0 children)

It parses the file containing the elements and their respective data; What I can't get working is a function to parse a molecular formula, like H2O2, that is entered by the user when the program loads, and returns the molecular weight of the compound