Hello,

I have a txt file of the following format:

315151,34.56,1,1,54442221,23344445
512512,12.54,1,1,23444442,45612345

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

while( fgets( output,sizeof(output) ,file) != NULL ){
            i=0;
            token[i] = strtok(output,",");
            while( token[i] != NULL){
                i++;
                token[i] = strtok (NULL, ",");
            }
            dec2bin(atol(token[4]),binaryBefore);
            dec2bin(atol(token[5]),binaryAfter);

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?

cheers

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.