Hello guys, i'm new here. I would like to convert my .txt file which have the following content into an array of int which every elemnt in the array should only have 4 character inside.

example:

two[1]= 0x03;
two[2]= 0x00;
two[3]= 0x03;
two[4]= 0xf5;

This is the content of my file:

0xf50x000x000x000x100x230x210x2c0x410x290x220x980x410x2d0x2e0x9b0xa10x2e0xa60x820xa10x3d0x1f0x980x410x44

You might have to read it in as a string the parse it with something like strtok()

/* This code might help you */
main()
{
    FILE *fp;
    char c,d[3];
    int i,j,two[][4];
    fp=fopen(filename.txt,"r");
    for(i=0; !feof(fp); i++)
    {
        for(j=0; j<=3; j++)
        {
        c=fgetc(fp);
        c=fgetc(fp);
        d[0]=fgetc(fp);
        d[1]=fgetc(fp);
        d[2]='\0';
        two[i][j]=atoi(d);
        printf(" %02x",two[i][j]);   /*to output in hexadecimal format*/
       }
   }
 getch();
 }

This code might help you

No it won't, the string contains hex values which atol() doesn't understand. But you can use strtol()

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.