CSV Reader in C programming
$20-25 USD
Publicado hace más de 15 años
$20-25 USD
Pagado a la entrega
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;
}
ID del proyecto: 3631216
Información sobre el proyecto
47 propuestas
Proyecto remoto
Activo hace 15 años
¿Buscas ganar dinero?
Beneficios de presentar ofertas en Freelancer
Fija tu plazo y presupuesto
Es gratis registrarse y presentar ofertas en los trabajos
47 freelancers están ofertando un promedio de $14 USD por este trabajo
$17 USD en 3 días
4,9 (671 comentarios) $21,25 USD en 3 días
4,8 (441 comentarios) $21,25 USD en 3 días
4,9 (59 comentarios) $20,40 USD en 3 días
5,0 (6 comentarios) $21,25 USD en 3 días
5,0 (52 comentarios) $17 USD en 3 días
4,8 (26 comentarios) $21,25 USD en 3 días
5,0 (28 comentarios) $12,75 USD en 3 días
4,6 (70 comentarios) $6,80 USD en 3 días
4,9 (125 comentarios) $21,25 USD en 3 días
4,7 (33 comentarios) $17 USD en 3 días
4,8 (34 comentarios) $13,60 USD en 3 días
5,0 (32 comentarios) $12,75 USD en 3 días
4,7 (19 comentarios) $17 USD en 3 días
5,0 (42 comentarios) $12,75 USD en 3 días
5,0 (5 comentarios) $20,40 USD en 3 días
4,6 (26 comentarios) $21,25 USD en 3 días
5,0 (16 comentarios) $20,40 USD en 3 días
4,8 (7 comentarios) $21,25 USD en 3 días
3,8 (13 comentarios) $12,75 USD en 3 días
4,6 (20 comentarios)