Last active
August 29, 2015 14:10
-
-
Save forsythetony/aa7d2c3f635f15d3a4e5 to your computer and use it in GitHub Desktop.
nothing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sqlite3.h> | |
#include <string.h> | |
#define BUFFERSIZE | |
int checkIfFileExists( char* fileName ); | |
int countColumnsInLine( char* line ); | |
int main(int argc, char** argv) | |
{ | |
if(argc != 4) | |
{ | |
fprintf( stderr, "USAGE: %s <database file> <table name> <CSV file>\n", argv[0] ); | |
return 1; | |
} | |
// Check to see if the file is available for writing | |
if( checkIfFileExists( argv[3] ) != 0) { | |
printf( "\n The file could not be opened for reading.\nExiting program now.\n"); | |
return -2; | |
} | |
else | |
printf( "\nThe file %s was found and can be read!\n", argv[3] ); | |
char *line, *record; | |
char buffer[1024]; | |
int i = 0; | |
FILE *file = fopen( argv[3], "r" ); | |
char *temp; | |
while( fscanf( file , "%s", buffer ) != EOF ) { | |
printf( "%s\n", buffer ); | |
temp = buffer; | |
int count = countColumnsInLine( buffer ); | |
printf( "\nThere are %d records in that line.\n", count ); | |
} | |
return 0; | |
} | |
int checkIfFileExists( char* fileName ) { | |
FILE *file; | |
if( ( file = fopen( fileName, "r")) == NULL ) { | |
return -1; | |
} | |
else | |
return 0; | |
} | |
int countColumnsInLine( char* line ) | |
{ | |
char delim = ','; | |
int count = 0; | |
while( *line ) | |
{ | |
if( *line == delim ) | |
{ | |
count++; | |
} | |
line++; | |
} | |
return ( count + 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment