I am new to C programming but have a bit of Java knowledge, so I want to write a program that reads strings stored in a file, possibly several names separated by comma, such as "boy","girl","car" etc. In Java I would use something like, string str[]=str1.split(" ");.
So I came up with several codes each time but none seems to work, here is my most recent code:
fscanf(fp,"%[^\n]",c); But this essentially prints the whole line till a new line is found. I have also tried using
fscanf(fp,"%[^,]",c); And if I use gets() it only gets the first string and ignores all others from the first comma.
This didn't give any reasonable output, it rather gave some minute(encoded) characters. Please can anyone help me with how to pick out string values separated by comma and in quotes
scanf()!strchr()andstrtok_r()are just fine.scanfis the solution. The call is made for reading formatted input.