[SOLVED] Need Help with - Warning: integer constant is too large for its type

Status
Not open for further replies.

wtr

Full Member level 5
Joined
May 1, 2014
Messages
299
Helped
29
Reputation
58
Reaction score
25
Trophy points
1,308
Activity points
4,108
Hello

I have the following in C


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
char byte_16[16];
  bool write = false;
  while (fread(&byte_16,16,1,fp_r) != 0) {
    if (byte_16 == 0xAAAAAAAAAAAAAAAAAAAAAAAA43210033) {
      write = true;
    }
    if (write) {
      fwrite((void*) byte_16, 16, 1, fp_w_tmp);
    }
  }



The error message the compiler is giving me is
Warning: integer constant is too large for its type

I tried unsigned long long. Alas it did not work.
I want to be able to read in a binary file & when I see (hex)AAAAAAAAAAAAAAAAAAAAAAAA43210033 I want to output the following to an out file.


Thanks in advance
Regards
Wes
 

A legal C construct to check the data read into byte_16 could use memcmp().

The long hex value is surely no correct literal for an array of char. You should also consider that byte_16 is already representing a pointer.
 
Reactions: wtr

    wtr

    Points: 2
    Helpful Answer Positive Rating
Thanks Fvm,

I hope you've sent me down the right path.

So essentially the way I've tried to do this is

1. Read from a file (binary) into a buffer - unsigned char byte_16[16]
2. Compare that part of byte_16 matches an identifier (hex value AAAAAAAAAAAAAAAA)

I've tried
if ((memcmp(byte_16, 0xAAAAAAAAAAAAAAAA, 8)) == 0)

However this returned compiler error
warning: passing argument 2 of 'memcmp' makes pointer from integer without a cast
I can do
if (byte_16[1] == 0XAA) && (byte_16[2] == 0XAA) ...etc
and it works...but I don't think very elegant
 

The compare string should be implemented as constant array. As you wrote it, the literal is interpreted as a pointer value and respectively truncated (e.g. to 32 bit). Can't work as intended.

Code:
constant char comp_16[] = {0xAA,0xAA, ....};
 
Reactions: wtr

    wtr

    Points: 2
    Helpful Answer Positive Rating
Nvm I found my problem was with the way I was declaring my char to compare

the following fixed it.

Code C - [expand]
1
2
3
4
char Identifier[] = "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
  while (fread(&byte_16,16,1,fp_r) != 0) {
    if ((memcmp(byte_16, Identifier, 8)) == 0) {
      write = true;



Will mark this thread as solved
 

The compare value in post #1 doesn't look like a string because it has a zero in the middle. That's why suggested memcmp() instead of strcmp().
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…