Find Jobs
Hire Freelancers

CSV Reader in C programming

$20-25 USD

Closed
Posted about 15 years ago

$20-25 USD

Paid on delivery
I have the start of a simple CSV C program, that reads the file, parses it, then displays it. The code is 80% done but there is a litte bit of code that needs to be added to read the file and there may be other errors. I would like someone to finish the program so it works without errors. ## Deliverables This is the code I currently have: #include <stdio.h> #include "stdafx.h" int main(int argc, char ** argv){ ? int c; ? FILE * fp; ? if(argc < 2){ ? ? ? printf("Usage:\n\t%s filename\n",argv[0]); ? ? ? return -1; ? } ? if((fp = fopen(argv[1],"rb")) == NULL){ ? ? ? printf("can't open %s\n",argv[1]); ? ? ? return -2; ? } ? while((c = fgetc(fp)) != EOF){ #define MAX_LINE_LEN? ? 1024*512? // 1/2 mega byte, should be more than sufficient */ ? ? ? char line[MAX_LINE_LEN]; ? ? int len=0; ? ? int cnt_of_fields=0; ? ? char *p; ? ? while( (c=GET_A_CHAR_FROM_FILE(fp))!=EOF){ ? ? ? ? ? ? ? ? ? ? switch(c) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? case '"': ? ? ? ? ? ? ? ? ? ? case '\'': ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // parse a quoted string, ignore it for now */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? case ',': ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ++cnt_of_fields; // a comma signal end of previous field and begining of next fields */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? line[len++]='\0'; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(len==MAX_LINE_LEN){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fprintf(stderr, "Line too long\n"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exit(-1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? case '\n': ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ++cnt_of_fields; // a EOL is end of record, and at the same time end of field */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? line[len++]='\0'; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // make a copy of the line in the heap, note strdup or strcpy won't work in our case */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? p = (char *)malloc(len); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? memcpy(p, line, len); // now all the fields in the record are stored in p[ ] */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? add_a_record( p ); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? line[len++] = c; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(len==MAX_LINE_LEN){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fprintf(stderr, "Line too long\n"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exit(-1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? } ? ? ? printf( "%s", line ); ? } ? fclose(fp); ? return 0; }
Project ID: 3631216

About the project

47 proposals
Remote project
Active 15 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
47 freelancers are bidding on average $14 USD for this job
User Avatar
See private message.
$17 USD in 3 days
4.9 (671 reviews)
7.7
7.7
User Avatar
See private message.
$21.25 USD in 3 days
4.8 (441 reviews)
7.4
7.4
User Avatar
See private message.
$21.25 USD in 3 days
4.9 (59 reviews)
5.8
5.8
User Avatar
See private message.
$20.40 USD in 3 days
5.0 (6 reviews)
5.4
5.4
User Avatar
See private message.
$21.25 USD in 3 days
5.0 (52 reviews)
5.5
5.5
User Avatar
See private message.
$17 USD in 3 days
4.8 (26 reviews)
5.3
5.3
User Avatar
See private message.
$21.25 USD in 3 days
5.0 (28 reviews)
4.5
4.5
User Avatar
See private message.
$12.75 USD in 3 days
4.6 (70 reviews)
5.0
5.0
User Avatar
See private message.
$6.80 USD in 3 days
4.9 (125 reviews)
5.0
5.0
User Avatar
See private message.
$21.25 USD in 3 days
4.7 (33 reviews)
5.0
5.0
User Avatar
See private message.
$17 USD in 3 days
4.8 (34 reviews)
4.4
4.4
User Avatar
See private message.
$13.60 USD in 3 days
5.0 (32 reviews)
4.3
4.3
User Avatar
See private message.
$12.75 USD in 3 days
4.7 (19 reviews)
4.2
4.2
User Avatar
See private message.
$17 USD in 3 days
5.0 (42 reviews)
3.7
3.7
User Avatar
See private message.
$12.75 USD in 3 days
5.0 (5 reviews)
3.8
3.8
User Avatar
See private message.
$20.40 USD in 3 days
4.6 (26 reviews)
4.2
4.2
User Avatar
See private message.
$21.25 USD in 3 days
5.0 (16 reviews)
3.8
3.8
User Avatar
See private message.
$20.40 USD in 3 days
4.8 (7 reviews)
3.9
3.9
User Avatar
See private message.
$21.25 USD in 3 days
3.8 (13 reviews)
4.8
4.8
User Avatar
See private message.
$12.75 USD in 3 days
4.6 (20 reviews)
3.6
3.6

About the client

Flag of UNITED KINGDOM
Bristol, United Kingdom
4.1
70
Payment method verified
Member since Apr 25, 2012

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.