Ok, I'm writing a tool that opens a file, reads data, and then prints it, my problem is, I can't figure out how to use the function headerData() correctly, and someone at some point told me also I'm comparing a string when I should be assigning it to an int, or something like that.
I'm very new at this, and just started a couple days ago.
With this code, I want it to print interpreted data read from a file:
File Loaded
Head String: Ehed
However I'm getting an error on line 14:
* if (headString = "Ehed") {*
Assignment makes integer from pointer without a cast.
I'm afraid I don't understand,
Could someone give me an example of the correct way to do this, and explain what I am doing wrong, and what I should be doing instead?
Thanks!
I'm very new at this, and just started a couple days ago.
With this code, I want it to print interpreted data read from a file:
File Loaded
Head String: Ehed
However I'm getting an error on line 14:
* if (headString = "Ehed") {*
Assignment makes integer from pointer without a cast.
I'm afraid I don't understand,
Could someone give me an example of the correct way to do this, and explain what I am doing wrong, and what I should be doing instead?
Thanks!
Code:
#include <stdio.h>
#include <stdint.h>
int main( int argc, char *argv[] )
{
FILE *fp;
uint32_t headString = headerData( headString );
if (fp = fopen( "PathToFile", "r+"))
{
printf("File Loaded");
headerData( headString );
if (headString = "Ehed") {
printf("Head String: %c%c%c%c\n", headString >> 24 & 0xFF, headString >> 16 & 0xFF, headString >> 8 & 0xFF, headString & 0xFF);
}
}
return 0;
}
uint32_t read_little_32(const unsigned char *p)
{
return p[0] | p[1] << 8 | p[2] >> 16 | p[3] >> 24;
}
int headerData( uint32_t argc, char *argv[], FILE *fp )
{
unsigned char uHeadString;
uint32_t headString;
fseek(fp, 0x2C0, SEEK_SET);
fread(&uHeadString, 1, 5, fp);
headString = read_little_32(&uHeadString);
return headString;
}
/*
In the file:
Assume 0x0 till 0x2C0 is just 00's.
2C0 - 2C4 in the file is 0x64656845 (ASCII - dehE)
assume from 2C5 - EOF = 00's.
*/