The string I am trying to parse is called str1, and it contains PRETTY_NAME="Ubuntu 20.04.1 LTS"
The goal is to have one variable contain PRETTY_NAME, and the other contains Ubuntu 20.04.1 LTS. I have declared both variables as char *var1, *var2
This has to be done with the sscanf function in C.
My current code looks like: sscanf(str1, "%s[^=]^s", var1. var2); The output I am receiving is that both var1, and var2 return (null).
What am I doing wrong?
char *catch_str;That's an uninitialized pointer, sosscanf(str1, "%s %s", catch_str, ...);is undefined behavior. Either change it tochar catch_str[100];or allocate it dynamically. Same goes formy_str, then after that you'll still have to fix thesscanfformat string."%[^=]=\"%[^\"]\"". Don't forget to check the return value ofsscanfto make sure that parsing succeeded.