Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C file read/write

  • 16-03-2007 02:17PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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