![]() |
|
[C] Grabbing each line from CSV to Struct - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Grabbing each line from CSV to Struct (/showthread.php?tid=5906184) |
Grabbing each line from CSV to Struct - Volitair - Nov 11, 2018 Hey guys, I recently started to work with C in school and I am trying to make a program which can read each line from a CSV file and store it in a struct named "Products". The struct must be able to handle up to 100 products in total (The product.csv file contains 50 lines of products). So far this class that I have can read one line from the CSV file, and it only grabs the first line. If I use fgets again, it will overwrite the first line and give me the second line which is not what I need. This is what the assignment says: The input file products.csv contains about 50 items. Each single row corresponds to a product. A loaded line must be saved in one struct, with the name being, with content as above (The struct at the bottom of the thread). Create a field with these commodities with space for 100 pieces of goods. So far this is the code I have: Code #include <stdio.h>The struct must contain the following items: Code struct productAny ideas on how I can proceed to grab each line using a loop or something and store them in a struct? I am willing to pay in bitcoin if someone could help me out with this :) Thanks! RE: Grabbing each line from CSV to Struct - HFDone - Nov 11, 2018 struct product products[100] loop the lines count and sign the products array properties with your data |