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 7841011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:00:11+00:00 2026-06-02T16:00:11+00:00

I am trying to run the following code in Visual stuido. Please execute this

  • 0

I am trying to run the following code in Visual stuido. Please execute this code and then read my experience in below the code typed here.

#include <stdio.h>
#include <conio.h>
main()
{
int i;
struct book
{
    char name;
    float price;
    int pages;
};
struct book b[3];
printf("Enter the names prices & no. of pages of 3 books \n");
for (i = 0; i<=2; i++)
{
    printf("name of book %d : ", i +1);
    scanf("%c", &b[i].name);
    printf("price of book %d : ", i +1);
    scanf("%f", &b[i].price);
    printf("pages in book %d : ", i +1);
    scanf("%d", &b[i].pages);
}
for (i = 0; i<=2; i++)
{
    printf("Name of book : %c, Price of book: %f, Pages in book : %d \n", b[i].name, b[i].price, b[i].pages);
}
printf("Press any key to continue");
getch();
 }
void linkfloat()
{
    float a =0, *b;
    b = &a;
    a = *b;
}

As you can see it asks user the book name, pages nos and price, but it so happens that when you run code in visual basic, it doesn not allow to type name for book b2 onwards while it allows user to type price and page no for the same book b[i], moving forward it prints a blank space for book name where it did not allow user to type the name.

  • 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-02T16:00:15+00:00Added an answer on June 2, 2026 at 4:00 pm

    This is one of the reasons you shouldn’t rely on scanf() for your input, because wrong inputs might screw up everything. I’m not sure what compiler you used before, but this code shouldn’t work in any standards compliant c compiler.

    When reading or printing strings, you have to use the format tag %s. %c stands for a single character only, so entering any name longer than one character will screw up all input requests following (unless handled properly, e.g. by flushing stdin).

    In a similar fashion, your name member might only store one character – not a complete name. Change it to an array, e.g. char name[64]. Make sure it’s long enough to store the complete name (and to avoid buffer overruns).

    There might be other mistakes, but I think those are the most significant ones keeping you from finding any other issues (if there are any).

    Edit:
    Tried the code and the issues happen due to the line break (from hitting return) still sitting in stdin. When reading an integer or float, it is skipped (due to not forming valid input), but it’s accepted for %c (didn’t check it, but if you do, you should notice the value read should be equal to \n).

    To fix this, always call fflush(stdin); after you’ve read using scanf(). Doing it right before reading the character should be enough, but it’s still a bit error prone.

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

Sidebar

Related Questions

I am trying to run the following code (which I got from here ).
Following is my code, I am trying to run it in Visual Studio. #include
when I trying to run following code. var result = from c in db.brand
I am trying to run the following code from within Eclipse: Process process =
I am trying to run the following code in assembly: mov %si, %ax mov
I'm trying to run the following code, but get an error in the gameLoop
I am trying to run the following code: List<Integer> list = Arrays.asList(1,2,3); ArrayList<Integer> val
I am trying to run the following simple code, public abstract class Shape{ abstract
iam trying to run an application visual studio 2008.. got this error.. help me
I am getting access violation error when I run the following code on Visual

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.