I'm playing around with file pointers in preparation for the Recover Problem. I'm trying to understand something here. I can't actually open up the raw file to read on my IDE. And neither can I read it to make sense character-by-character as I tried in the code here.

Why does the following code print a bunch of gibberish and funky characters when I run it?

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
    char ch;

    FILE* stream = fopen("card.raw", "r");
    if(stream != NULL)
        for (int i = 0; i < 100000; i++)

                ch = fgetc(stream);
                printf("%c", ch);

1 Answer 1


It looks like gibberish because the code is printing it as if it were ASCII char data. In reality, it is literally raw digital data. It doesn't translate to ASCII codes or anything else. Instead, it represents either header data in a jpeg file or the digital representation of colors in pixels. It's really not printable.

So, first of all, you'd need to extract the jpeg files from the raw file to interpret their header data or pixel data.

However, if you really want to look at the raw data, look at the man page for a program called xxd.

Although, there is at least one hidden message in there! ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Haha, I saw the hidden message, always love easter eggs. xxd looks interesting. Do you have references to where I can read more about how "raw digital data" is created - in this case by a camera?
    – echorashmi
    Jul 20, 2020 at 4:42
  • just google it. "How are digital photos stored" or "how are digital photos created". Or "jpeg standard" or any other specific detail you want to know about.
    – Cliff B
    Jul 21, 2020 at 7:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .