While your drawing and your description are in conflict to a certain extent, it appears you want to be able store data for a number of Items or Files where each item coordinates a grocery value, a quantity value and a unitprice values (similar to what you would use for the basis of an inventory system).
From your drawing, your Filenr struct member doesn't make much sense. Why? If your base Item struct coordinates grocery, quantity, and unitprice, then unless the Filenr provides an additional unique bit of information that is part of that grocery, quantity, and unitprice, then it can simply be omitted and you can use its index to describe the grocery, quantity, and unitprice.
Further, being of type char, its value would be limited to one of 256 values (-128 - 127). If you are actually considering that to be a printable characters, then your range of values is reduced to just 96 printable characters.
You define your struct based on the data you have. If Filenr is a piece of data that is part of your input and is associated with grocery, quantity, and unitprice, then add it to your struct as a member. If it is just something you are using to refer to a unique struct, then it isn't needed -- UNLESS -- you can have two struct with the exact same values in grocery, quantity, and unitprice and you are using Filenr to disambiguate between two otherwise identical struct. Otherwise, omit it and use an index.
Without it, you would simply create an array of your structs. That would allow you to be able to sort, query and sum by any of the member values. A trivial implementation that prints the stored (made-up) values would be:
#include <stdio.h>
typedef struct { /* your struct using a typedef for convenience */
int grocery, quantity;
double unitprice;
} item;
/* simple function to output all n struct in any array of item */
void prn_items (item *items, size_t n)
{
for (size_t i = 0; i < n; i++)
printf ("\nFilenr[%2zu]:\n grocery : %d\n quantity : %d\n unitprice : %0.4f\n",
i, items[i].grocery, items[i].quantity, items[i].unitprice);
}
int main (void) {
item files[] = {{ 31756, 22, 1.3405 }, /* made-up example data for array */
{ 7818, 83, 2.4722 },
{ 17920, 63, 1.3795 },
{ 2937, 32, 2.8648 },
{ 8423, 44, 2.6031 }};
size_t n = sizeof files / sizeof *files; /* number of elements in array */
prn_items (files, n); /* output all struct */
}
Example Use/Output
Running the program simply outputs all stored struct values coordinated by index as the Filenr:
$ ./bin/grocerystruct
Filenr[ 0]:
grocery : 31756
quantity : 22
unitprice : 1.3405
Filenr[ 1]:
grocery : 7818
quantity : 83
unitprice : 2.4722
Filenr[ 2]:
grocery : 17920
quantity : 63
unitprice : 1.3795
Filenr[ 3]:
grocery : 2937
quantity : 32
unitprice : 2.8648
Filenr[ 4]:
grocery : 8423
quantity : 44
unitprice : 2.6031
Now if your intent was to save each of the struct in a separate file, you could simply create an output filename with sprintf() that contains a unique suffix (or prefix) based on the index.
If you really want a single char and Filenr as part of your struct, you can simply include it by adding it back as a member, e.g.
typedef struct { /* your struct using a typedef for convenience */
char Filenr;
int grocery, quantity;
double unitprice;
} item;
Adjust the reminder of the code to handle the additional member.
Lastly, you don't want to use a floating-point number related to price. (companies get mad when you lose money due to rounding error). Better to use an integer value multiplied accordingly to ensure rounding error doesn't occur. You can search "floating point type for money" and find a wealth of additional information on that topic.
Look things over and let me know if you have further questions.
struct file. Adding arrays withstruct filewould be counter-productive. You would lose the coordination amonggrocery,quantityandunitprice. An array ofstruct filewould preserve that coordination. (which is why you use a struct to begin with...)