Counter and printf

Hi all

I need a counter to to count up something

So I use follow code to do this work

unsigned long pdata counter[4]={0,0,0,0};

in the counting place,

counter[0]++;


when run finsih , I print the result

printf(%ld\n",counter[0]};


Maybe I have run to 1000 times ,so counter[0] value

will be to 1000 , but the printf result maybe very

large, like as 92343421;

why ?? how can I make sure to count up correctly??

Thanks a lot

best regards

Parents
  • printf(%ld\n",counter[0]};
    


    That line contains two typos and wouldn't even compile - so it is clearly not the actual code that you are using!

    You must you copy-and-paste to post your code!

    Post the smallest complete example that illustrates the problem.

    Have tested this in the Simulator?
    What debugging have you done?

    Are you sure your PDATA is working & correctly configured?

Reply
  • printf(%ld\n",counter[0]};
    


    That line contains two typos and wouldn't even compile - so it is clearly not the actual code that you are using!

    You must you copy-and-paste to post your code!

    Post the smallest complete example that illustrates the problem.

    Have tested this in the Simulator?
    What debugging have you done?

    Are you sure your PDATA is working & correctly configured?

Children
More questions in this forum