Code:
#include <stdio.h>
main()
{
   FILE *fp= fopen("binary.txt", "r"), *fp1=fopen("binary w spaces.txt","w");
 int x=-1,c;
 
 while((c = fgetc(fp))!=EOF)
 {
    x++;
    if (x==8)
       {
          fputc(' ',fp1);
           x=0;
       }
   fputc(c,fp1);
 }
 
 
}


I have this file (binary.txt) with lots of 1s and 0s I got from a bitmap image (I will explain below how I did this) and I want to separate each byte with a space, that's what the code above is for. It works like that, but if I initialize x as -2 and write x==9, it displays a bunch of gibberish like this:

Code:
㄰〰〰〱〱ㄠ〱㄰〰〱〠〱㄰㄰〱〠㄰㄰〰㄰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰㄰〠〱〰〱〰〠〰〰〰〰〠〰〰〰〰〠〰〰ㄱㄱㄠ〰〰〰〰〠〰〰〰〰〠〰〰〰〰ㄠㄱ㄰〱㄰〠〰〰〰〰〠〰〰〰〰〠〰㄰ㄱ〰〠ㄱ〱〰〰〠〰〰〰〰〠〰〰〰〰ㄠ〰〰〰〰〠〰〰〰〰〠〰〱〰〰〠〰〰ㄱ〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰㄰〰〰〠ㄱ〰㄰㄰〠〰〱〰〰〠〰〰㄰〱〠〱〰ㄱ㄰〠〰〰〰〰〠〰〰〰〰〠㄰〱㄰〰〠ㄱ㄰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰ㄱㄱㄠㄱ〱〰〰〠〰〰〰〰〠㄰ㄱㄱㄱㄠ〰〰〰〰〠〰〰〰㄰ㄠㄱㄱㄱ〰〠〰〰〰〰〠〰〰ㄱㄱㄠㄱ〱〰〰〠〰〰〰〰〠〰〰〰〰〠㄰〰〰〱ㄠㄱ〰㄰〰ㄠ〰〱〱ㄱ〠㄰ㄱ〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰㄰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰〰〰〠〰〰ㄱㄱㄠ㄰ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ〱ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ〱ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ㄰ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ㄰ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ〱ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ〱ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱ〠ㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ㄰ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ㄰ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ〱ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ〱ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ㄰ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ㄰ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ〱ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ〱ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱ〠ㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ㄰ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ㄰ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ〱ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ〱ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ㄰ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ㄰ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱ〱ㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱ〱ㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱ〠ㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ㄰ㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠ㄰ㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱㄱㄱㄠㄱㄱ〱


Why does this happen? What do those symbols mean?

EDIT:
About the bitmap thingy, I hid some files in an image, coverted it to .bmp, then I went to cmd and wrote "type image.bmp >> file.txt". Then I used a program to convert all those characters into 1s and 0s and then I wrote the above code to separate them into groups of 8. Come to think about it, it wasn't really necessary.

Anyways, I'm just experimenting with steganography.
You probably just need to change x=0; to x=1; as well. Smile Otherwise your bytes would be 9 bits in length. I really am not too sure about that though; I would have to test it.
Maybe the spaces in the file name are glitching out?
It sounds like you may have a non-ASCII file, and those -1/-2 values eliminate the BOM or other similar characters at the beginning of your file. Try opening the source file in your favorite simple text editor and store as a simple ASCII (not Unicode or ANSI) file.
KermMartian wrote:
It sounds like you may have a non-ASCII file, and those -1/-2 values eliminate the BOM or other similar characters at the beginning of your file. Try opening the source file in your favorite simple text editor and store as a simple ASCII (not Unicode or ANSI) file.


How do I do that?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement