A simple C-voice related issue

Source: Internet
Author: User
A simple C-voice problem.
The code is as follows:
#include
 
  
  
   

typedef unsigned char Us_char;

int main ()
{
Defining two-dimensional arrays for storing picture information
Us_char img[256][256];

FILE *FP = fopen ("31015_h1.raw", "WB");
if (!FP)
{
printf ("Erro");
return 1;
}


for (int i = 0; i<256; i++)
for (int j = 0; j<256; j + +)
IMG[I][J] = (Us_char) J;

Fwrite (IMG, sizeof (IMG), n, FP);//write

Fclose (FP);

return 0;
}

The output image is as follows:
If the file *FP = fopen ("31015_h1.raw", "WB"), the "WB" is changed to "B"
The output image is as follows:

This I can not think of the solution ah, the prawn could help me explain, thank you!
------to solve the idea----------------------
"WB" changed to "B" is less write.
It is estimated that 31015_h1.raw is a figure two.
------to solve the idea----------------------
FILE *FP = fopen ("31015_h1.raw", "B");
Isn't that a mistake?

Is that right?
FILE *FP = fopen ("31015_h1.raw", "w");

Your J cycle is from 0 to 255.
When j = 10 o'clock, (Us_char) j is the newline character, the window Chinese text line break will automatically add a carriage return character
So the whole thing was misplaced.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.