Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:40:48+00:00 2026-06-13T12:40:48+00:00

int main() { char buffer[100]; fread(buffer,1,4,stdin); int i=0; while(i<4) { printf (%c,\n,buffer[i]); i=i+1; }

  • 0
int main()

{


  char  buffer[100];
  fread(buffer,1,4,stdin);
  int i=0;
  while(i<4)

  {
    printf ("%c,\n",buffer[i]);

    i=i+1;
  }

 getch();

}

How the fread function will know,when to stop reading the input stream,what does the size and count elements signify,and how to manipulate size and count to get the maximum stream reading speed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:40:49+00:00Added an answer on June 13, 2026 at 12:40 pm

    To print all bytes in an int? Remember that an int is 32-bit, which is four bytes. Reading it into a char buffer makes it easier to access those four bytes in the int.

    Edit: Little explanation of the int type…

    Lets say you have an int:

    int someIntValue = 0x12345678;
    

    This is stored in 32 bits in the memory. As a single byte (char) is 8 bits, there are four bytes to an int. Each byte in the int can be accessed by using a char array or pointer:

    char *someCharPointer = (char *) &someIntValue;
    

    Now you can access those four separate bytes, and see their values:

    for (int i = 0; i < sizeof(int); i++)
        printf("someCharPointer[%d] = 0x%02x\n", i, someCharPointer[i]);
    

    The above will print (on a little-endian machine such as x86):

    someCharPointer[0] = 0x78
    someCharPointer[1] = 0x56
    someCharPointer[2] = 0x34
    someCharPointer[3] = 0x12
    

    If you now change someIntValue to the number 1

    someIntValue = 1;
    

    and print it out again, you will see this result:

    someCharPointer[0] = 0x00
    someCharPointer[1] = 0x00
    someCharPointer[2] = 0x00
    someCharPointer[3] = 0x01
    

    Memory layout of an int

    If you have a variable of type int stored in memory with the value 0x12345678, it’s stored like this:

       8 bits
    ,----^---.
    |        |
    
    +--------+--------+--------+--------+
    |00111000|01010110|00110100|00010010|
    +--------+--------+--------+--------+
    
    |                                   |
    `-----------------v-----------------'
                      |
                   32 bits
    

    This int is the same as the four bytes (or char) 0x78, 0x56, 0x34 and 0x12.

    However if we change the int to the number 1 then it’s stored like this:

       8 bits
    ,----^---.
    |        |
    
    +--------+--------+--------+--------+
    |00000000|00000000|00000000|00000001|
    +--------+--------+--------+--------+
    
    |                                   |
    `-----------------v-----------------'
                      |
                   32 bits
    

    This int is the same as the four bytes (or char) 0x00, 0x00, 0x00 and 0x01.

    So now you hopefully can see how reading as an int and printing as char will display a different result from reading and int and printing it as an int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
I have this code: int main() { char buffer[10]; if( buffer ) { return
int main() { char* NamePointer = new char; std::cout << Enter the file you
This code causes a Segmentation Fault: int main(){ char *p; char a[50] = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
I am writing some code in C: int main(){ char guess[15]; guess = helloValidation(*guess);
Here's my program so far: int main() { char choice = 'D'; string inputString;
Why does the following code seg fault before returning: int main() { char iD[20];
I have this quick sort implementation to sort the characters. int main(){ char val[]
#include<stdio.h> int main() { char *s[] = { knowledge,is,power}; char **p; p = s;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.