I have to parse different fields of PAT table in this file...
the file looks like this in hex editor...
47 40 00 10 00 00 B0 0D 00 00 C3 00 00 00 01 E0 21 63 0D 38 1E ......
my code is

    #include <stdio.h>
    #include <string.h>
    void main() {

    FILE *f;
    int num[50];
    short unsigned int i=0;
    short int rv;
    //short unsigned int num_values;
     if (f==0){
        printf("file doesnt exist?!\n");
     while (i<50) {

        rv = fscanf(f, "%d", &num[i]);

        //if (rv != 1)

    printf("table id = %d%d \n",num[10],num[11]);
    int section_syntax_indicator=num[12] & 0x0008;
    int secl = num[13] & 0x0001;
printf("section length= %d%d%d \n",secl,num[14],num[15]); printf("transportstreamid=%d%d%d%d",num[16],num[17],num[18],num[19]);
    int var1=num[20] & 0x0003;         
    int var2=num[21] & 0x000E;
    int currentnext=num[21] & 0x0001;    
    printf("version no=%d%d \n",var1,var2);
    printf("current_next=%d \n",currentnext);
    printf("section no=%d%d \n",num[22],num[23]);
    printf("last section number=%d%d \n",num[24],num[25]);
    int var3=num[30] & 0x0001;    printf("programmapid=%d%d%d%d\n",var3,num[31],num[32],num[33]); 


the output im getting is:

table id = 00
section_syntax_indicator= 0
section length= 036625504
transport stream id =0012190version no=00
section no=1345133176688432
last section number=1345131321
program number=6623172-10792550886625944-1079255132
program map pid=0-1079255148134513132-1079255160

can anyone suggest me where the problem is?.thanks in advance.

Recommended Answers

All 5 Replies

if (f==0){
        printf("file doesnt exist?!\n");

f is a pointer. Your if condition should check whether it is null. And if so print the message and exit.

Also since you are reading a file that contains hexadecimal numbers , it will contain characters from A to F and in fscanf you are reading integers. use %x as format specifier and see if it works

tried both ,but it is not working,giving wrong values...

Just to confirm, you modified the format specifiers in printf as well, right?

Just to confirm, you modified the format specifiers in printf as well, right?


Be a part of the DaniWeb community

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