Question

I'm having trouble working with a .csv file in C Programming. I know that I need...

I'm having trouble working with a .csv file in C Programming. I know that I need to use parallel arrays to search through the data but I am a little lost.

How would I go through the data in a file, for example I created one and attached it. To find the information between two dates.

So Ask the user for two dates then search the .csv file for that and give an output similar to:

"Select the starting and ending dates for the data to work with.

Start date: 10-May-2014

End date: 5-June-2014

Dates selected are from 20-May-2014 through 5-Jun-2014, inclusive. 5 records have been read into the array (out of 60)."

I really need help reading strings into arrays for the date and using that information to search a file. Please help!

Case Number,Date,Year,Type,Country,Area,Location,Activity,Name,Sex ,Age,Injury,Fatal (Y/N),Time

942365.c,25-Jun-14,2014,Athletic,USA,Western Cape Province,"New Smyrna Beach, Volusia County",Running,Jimmy Dean,M,42,Broken Leg,N,8:00

942215.b,18-Jun-14,2014,Athletic,USA,Western Cape Province,"New Smyrna Beach, Volusia County",Bicycling,Sheila O'Malley,F,37,Broken Leg,N,9:15

1548632,18-Jun-14,2014,Athletic,USA,Western Cape Province,"New Smyrna Beach, Volusia County",LaCrosse,Gertrude Stein,F,33,Broken Leg,N,12:00

2016.09.18.b,Reported 17-Jun-2014,2014,Athletic,USA,Western Cape Province,Thirteenth Beach,Swimming,Frida Kahlo,F,29,Broken Leg,N,1:00

2016.09.18.a,9-Jun-14,2014,Athletic,USA,Queensland,Bells Beach,Skiing,Gilbert Grape,M,37,Broken Leg,N,4:00

2016.09.17,9-Jun-14,2014,Athletic,USA,Western Cape Province,Bunbury,Running,Jimmy Stevens,M,61,Broken Leg,N,7:00

2016.09.15,9-Jun-14,2014,Athletic,USA,Florida,"Ponte Vedra, St. Johns County",Bicycling,Tyler Carr,M,8,Broken Leg,N,6:00

2016.09.15.R,8-Jun-14,2014,Athletic,ITALY,North Island,"Makaha, Oahu",LaCrosse,Douglas Diamond,M,19,Broken Leg,N,7:30

2016.09.11,7-Jun-14,2014,Athletic,SOUTH AFRICA,Hawaii,Koumac,Swimming,Jon Bon Jovi,M,11,Broken Leg,N,12:15

2016.09.07,1-Jun-14,2014,Athletic,SOUTH AFRICA,South Australia,"Kingston Plantation, Myrtle Beach, Horry County",Skiing,Felicia Miller,F,54,Broken Leg,N,9:08

2016.09.06,1-Jun-14,2014,Athletic,SOUTH AFRICA,California,Injidup ,Running,Kyle Thomas,M,42,Broken Leg,N,6:27

2016.09.05.b,1-Jun-14,2014,Athletic,AUSTRALIA,New South Wales,"New Smyrna Beach, Volusia County",Bicycling,Johnny James,M,26,Broken Leg,N,5:45

2016.09.05.a,24-May-14,2014,Athletic,USA,New South Wales,"Refugio State Beach, Santa Barbara County",LaCrosse,Sylvia Plath,F,29,Broken Leg,N,2:15

2016.09.04,23-May-14,2014,Athletic,AUSTRALIA,KwaZulu-Natal,"New Smyrna Beach, Volusia County",Swimming,Thomas Tyler,M,33,Broken Leg,N,2:43

2014.05.14,22-May-14,2014,Athletic,SOUTH AFRICA,Queensland,"New Smyrna Beach, Volusia County",Skiing,DeeDee Ann,F,42,Broken Leg,N,9:16

2015.11.20,20-Nov-15,2015,Athletic,BANGLADESH,Florida,Boucan Canot,Running,Teresa Ciccone,F,24,Broken Leg,N,4:11

2014.05.15,15-May-14,2014,Athletic,SOUTH AFRICA,Western Cape Province,"Ponte Vedra, St. Johns County",Bicycling,Jeri Tomlin,F,50,Broken Leg,N,3:00

0 0
Add a comment Improve this question Transcribed image text
Answer #1

for opening a text file

#include<stdio.h>

                int main()

                {

                                FILE *ptr_file;

                                int x;

                                ptr_file =fopen("output.txt", "w");

                                if (!ptr_file)

                                                return 1;

                                for (x=1; x<=10; x++)

                                                fprintf(ptr_file,"%d\n", x);

                                fclose(ptr_file);

                                return 0;

                }

For reading a text file

#include<stdio.h>

                int main()

                {

                                FILE *ptr_file;

                                char buf[1000];

                                ptr_file =fopen("input.txt","r");

                                if (!ptr_file)

                                return 1;

                                while (fgets(buf,1000, ptr_file)!=NULL)

                                printf("%s",buf);

                                fclose(ptr_file);

                                return 0;

                }

Add a comment
Know the answer?
Add Answer to:
I'm having trouble working with a .csv file in C Programming. I know that I need...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT