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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:29:32+00:00 2026-06-08T10:29:32+00:00

What is the error in my program? This is the code: /* * courseProject.c

  • 0

What is the error in my program? This is the code:

/*
 * courseProject.c
 *
 * It is a simple database for record shop
 * to track its iventory of CDs
 *
 * by Mahmoud Emam, 2012.
 */
#include<stdio.h>

main()
{
      /*
       * CDs infrormations
       */
      char title[31], artist[31];
      short int numberOfTracks;  /* short to save memory */
      int albumOrSingle;         /* Boolean to check 1 for Album and 0 for Single */
      float price;

      printf("Hello, Welcome to Record Shop!\n\n");
      /*
       * Asking for CD details
       */
      printf("Enter CD details\n\n");
      printf("CD's Title: ");
      scanf("%[^\n]", title);
      fflush(stdin);

      printf("CD's Artist: ");
      scanf("%[^\n]", artist);


      printf("Number of tracks: ");
      scanf("%d", &numberOfTracks);


      printf("Please press \"1\" for album, \"0\" for single: ");
      scanf("%d", &albumOrSingle);


      printf("CD's Price: ");
      scanf("%f", &price);

      /*
       * Output CD details
       */
      printf("\nCD details:\n");
      printf("=============\n\n");

      printf("CD's Title: <%s>\n", title);
      printf("CD's Artist: <%s>\n", artist);
      printf("Number of tracks: <%d>\n", numberOfTracks);

      if (albumOrSingle)
         printf("This is <Album>\n");
      else
         printf("This is <Single CD>\n");

      printf("Its price = <%.2f>\n", price);
      printf("=============\n\n");

      /* Exit from program */
      printf("Press any key to exit\n");

      fflush(stdin);
      getchar();
}

This is a simple program that reads CD info from the user and outputs the details again on the screen. However, the artist variable is always empty. Why?

I made printf("%s", artist); after I read it from the user and it works correctly, but it doesn’t work at the end of the program. The variable is always empty.

  • 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-08T10:29:34+00:00Added an answer on June 8, 2026 at 10:29 am

    The variable numberOfTracks is a short int, but you are reading it with scanf‘s %d specifier, which reads an int. This leads to undefined behavior – in this case it probably overwrites other variables such as artist.

    Either use the %hd specifier (which reads a short int), or change the variable to an int.

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

Sidebar

Related Questions

When adding this code to a simple calculator program I receive the error message
with this code, my program just force close(error) ***public View x = findViewById(R.string.nfoname);*** @Override
Im trying to use Date Formatters (NSDateFormatter), but I keep getting this error: Program
I am getting ERROR when I am running this program at the line static
I got this error Unhandled exception at 0x0049b946 in Program.exe: 0xC0000005: Access violation reading
I encounter error like this in my sql in running my program, How can
My iPhone app started logging this error: lo->hi recycling invariant violated! followed by: Program
Everytime I run the program, this mysterious error pops up saying that I have
I am trying to run a program and SOMETIMES I'm getting this error when
when I'm trying to compile my c program it gives me this error warning:

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.