Array or Structs? and using sscanf
I have two questions:
1. Can I have an array of structs and if so, how do I define it? I know how to define a struct, but not an array of structs if its possible.
2. If I have a csv string containing 2 ints and a string. how can I separate them using sscanf? An example format of the string is "0,5,TEST" I was reading on sscanf and saw that if there is a space, it will only take the value up to the space so do i need to make the string "0 5 TEST" instead of using csv and do 3 separate sscanf using %d %d and then again using %s???
and the Hat of Guessing
1. Of course. You put [how_many_do_you_want] after the name, just like every other array.
2. Your format should match the data. If your data is number,number,word then that's what your format should be: "%d,%d,%s". (Now if your word can have a space in it then we'd have to deal with that.)
2. So since there are commas separating the values, sscanf will recognize the commas in the format string and not include them in the data?
Yup. The format string is a template of how the input is scanned. There may be fancier format parameters available such as “regular expressions” if you wish to allow multiple separator characters. But for simple commas, this will do.