Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C file read/write

Options
  • 16-03-2007 2:17pm
    #1
    Registered Users Posts: 143 ✭✭


    Hi,
    i'm trying to read in hex values generated by one program into another.
    I start by writing the values to file using redirection as:

    outputfile.exe > random.dat

    then I'm trying to use the following code to read in the values

    fp = fopen("random.dat", "rb");
    int getc(FILE *fp);
    char c=0;

    for(int i=0;i<sizeOfArray;i++)
    {

    while((c=fgetc(fp))!=EOF){
    c=fgetc(fp);
    input_Array=c;
    printf("\n%x",input_Array);
    i++;
    }

    }
    My output from printf isn't the hex values. It appears ot be ASCII equivalents for the hex values. When I open the file it look slike the data is correct. How do I get the hex values from the file back into an array where I can manipulate them?

    Thanks

    L


Comments

  • Registered Users Posts: 26 ast


    Have a look at the fread function.

    http://www.cprogramming.com/tutorial/cfileio.html is the best reference I managed to find. Hope this helps.


  • Registered Users Posts: 441 ✭✭robfitz


    Lars wrote:
    i'm trying to read in hex values generated by one program into another.

    Can you give us an example of the first programs output? For example something like this:
    01 34 8f ae 00 26 c7 82 ab ....

    So for this example the basic steps are, read the first character, convert to a number, shift number by 4 bits, read the second character, convert to a number, add the two numbers, skip white space, and repeat until the end of the file.


Advertisement