Start New Discussion within our Software Development Community


I have a txt file of the following format:


I am using the following code to parse it and it works:

while( fgets( output,sizeof(output) ,file) != NULL ){
            token[i] = strtok(output,",");
            while( token[i] != NULL){
                token[i] = strtok (NULL, ",");

dec2bin is a function that convert last two numbers into binary and also working.

But i want to insert this data into mySQL using: token[0].token[1],token[2],token[3],binaryBefore,binaryAfter.

Any one could help with any function or something?


Have you created the database and tables yet? What's the name of the table, and whats the names of the columns?

You need to learn the SQL (Structured Query Language). google for tutorials.

Briefly, if you want to insert a row into a table

INSERT INTO tablename VALUES(1,2,3,4,5)

Where 1,2,3,4, and 5 are just the values you want to insert for each of the columns in the table. 1 will be put into the first column, 2 into the second, etc.

If you want to insert text strings instead of numeric data then the strings have to be surrounded with ' character

char cmd[255];
sprintf(cmd,"INSERT INTO tablename VALUES('%s','%s','%s','%s');", tokens[0],tokens[1],tokens[2],tokens[3]);

With that, you have to call the mysql c api function to process the statement. I'm not going to tell you how that is done -- read the tutorials that are on the mysql web site.

This article has been dead for over six months. Start a new discussion instead.