3 Replies - 201 Views - Last Post: 19 November 2012 - 05:38 PM Rate Topic: ***-- 2 Votes

#1 sumsar1812  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-November 12

C Design ?

Posted 19 November 2012 - 05:12 PM

Hi again Guys.
I am doing a exam project and I'm in doubt of how i should proceed my code.

What the code is supposed to do is
1: read a file where each line is info about a football match(like score,teams,date and so on)
2: put each match into a datastructur
3: check the datastructor for some conditions out from userinput.

So I won't say im stuck at any of the points but my problem is how is the optimal way to do step 2. For me there is 2 ways
I can make alot of functions(like assignTeam,assignScore,assignDate and so on) or I can make one function where i add the info at once to the structure.
I kinda want to do the first way because it looks better and is easier to read, but in each of this function i use the same for loop and therfor could i just make it all in one function.

So yea what do you guys think I should do, many functions or, a single big function or maybe a 3th way?

Sorry if my english isn't the best but english isn't my first language.

Is This A Good Question/Topic? 0
  • +

Replies To: C Design ?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10804
  • View blog
  • Posts: 40,278
  • Joined: 27-December 08

Re: C Design ?

Posted 19 November 2012 - 05:24 PM

Take a look into structs. If you are already familiar with basic OOP, a lot of the same basic concepts are applied here. Then you will want to store an array of FootballMatch objects.
Was This Post Helpful? 0
  • +
  • -

#3 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: C Design ?

Posted 19 November 2012 - 05:31 PM

Use an array of structs, and add all your info to the struct members, in one function. Then use the info in the struct, to output any requested info.

readData() might be one function. answerQuery() might be another function. Don't make just one big function. Break them up according to what the functions are intended to do.

This post has been edited by Adak: 19 November 2012 - 05:32 PM

Was This Post Helpful? 1
  • +
  • -

#4 sumsar1812  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-November 12

Re: C Design ?

Posted 19 November 2012 - 05:38 PM

View PostAdak, on 19 November 2012 - 05:31 PM, said:

Use an array of structs, and add all your info to the struct members, in one function. Then use the info in the struct, to output any requested info.

readData() might be one function. answerQuery() might be another function. Don't make just one big function. Break them up according to what the functions are intended to do.


Yea i did make the array of structs allready but was just not sure how to get the in there, but now I know Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1