1

Part of the text file used:

Maths       H   B2 
Irish       O   C3 
English     O   B1

I am trying to split the strings into three arrays storing for example; maths into a subject array, H(higher level) into a level array and B2 into a grade array. Im doing this so it is then accessible later and easier to sort separately etc. The following is a code of me trying to split the strings in the array into three but want to store each one in a different array. This is my first assignment using structs so am new to this syntax and do not know how to do it.

SubjectResult split;

for(i=0; i<lineNum; i++){
    sscanf(ResultsArr[i],"%s %s %s",split.subject, split.level, split.grade);
}

Thanks in advance!

1 Answer 1

1

You need to make an array of structs.

SubjectResult split[MAXLINES];

for (i = 0; i < lineNum; i++) {
    sscanf(ResultsArr[i],"%s %s %s", split[i].subject, split[i].level, split[i].grade);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! would the strings be automatically broken up into three and stored in them array of structs then?
Your sscanf already splits them into 3. All I added was the way to keep them all in an array.
Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.