C: trouble understanding this files/struct based instruction

I'm trying to create a program that will ask the user to enter a name(it is assumed that every name will be 30 characters in length or less). It will then find the popularity of the name between 1921 and 2010 and print out a chart and graph. The program will then ask the user if they wish to do another analysis and repeat the process.

There are about 7 different functions that need to be used for this program, but I'm having trouble understanding 2 of the functions that I need to use.

Function 1:

int getRawData(FILE* fp,struct NameRecord records[],int currSize);`

function is passed a pointer to a file that is already open for reading. Each line in this file will be of the form (the names are fully capitalized in the file):

year,NAME,frequency

The function is also passed an array of NameRecord structs (records) and the number of records currently in that array (currSize). this function will read the data from the file into the array placing it at the end of the array (first record from file will be placed into array[currSize]). Function will return total number of records in the array after reading in the file.

  struct NameRecord{
          char name[31];
          int year;
          int frequency;
        }

Now I'm not sure if this means that I need to create a new array within the function that receives the records from the file or if it's something else entirely and I'm not reading the instructions correctly.(the file in this case is malebabynames.csv)

2nd function:

void setYearTotals(struct NameRecord records[], int size, int yearRangeTotal[]);

function is passed an array of NameRecords (records) and the size of that array (size). It is also passed an array called yearRangeTotal which will be used to store the total population for a given year range.

yearRangeTotal[0] holds the total population between 1921 to 1925
yearRangeTotal[1] holds the total population between 1926 to 1930
yearRangeTotal[2] holds the total population between 1931 to 1935
...
yearRangeTotal[17] holds the total population between 2006 to 2010

Solutions

(1) No, just fill in the array that is passed. This isn't different than passing fread an array of char (or anything else) and asking it to read N items. Check the return code to know how many were actually read.

(2) Less clear. I would guess you are being asked to iterate through the NameRecord array and increment the appropriate yearRangeTotal element based on the "year" field in NameRecord.year.

Tags: C / Arrays / File

Similar questions

Getting instruction given address pointed by the instruction pointer
I am working on this code where, I need to get the instructions executed by a program, given the instruction pointers. Assume for now that I have a mechanism that provides me addresses of the instructions, would it be possible to get the opcode from this (on an IA32 instruction set) ?
How to check if instruction is a PHI instruction in LLVM IR
I am writing an LLVM pass. For an instruction (llvm::Instruction Class), how can I check if an instruction is a PHI instruction?
Find which assembly instruction caused an Illegal Instruction error without debugging
While running a program I've written in assembly, I get Illegal instruction error. Is there a way to know which instruction is causing the error, without debugging that is, because the machine I'm running on does not have a debugger or any developement system. In other words, I compile in one machine and run on another. I cannot test my program on ...
How can I write a single instruction to switch two values into a variable every time the instruction is being executed?
I'd like to write a single instruction to switch two values into a variable at every instruction execution; this is the generic case: having two values x1, x2 and i initialized to x1 or x2, switch i value between x1 and x2 at every instruction execution, i.e. i= x1, x2, x1 ...; or, if i is initialized to x2, i = x2, x1, x2, ...; E.g. to switch betw...
What does an lea instruction after a ret instruction mean?
I found x86 lea instructions in an executable file made using clang and gcc. The lea instructions are after the ret instruction as shown below. What are these lea instructions used for? There is no jmp instruction to the lea instructions. My environment is Ubuntu 12.04 32-bit and gcc 4.6.3.
Translate Instruction Pointer Address (in shared library) to Source Instruction
Are there any tools or libraries one can use on Linux to get the original (source) instruction only from the PID and the current instruction pointer address, even if the IP currently points into a shared library? AFAIK it should be possible, since the location of the library mapping is available through /proc/[PID]/maps, though I haven't found any ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.