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

  • Home
  • SEARCH
  • 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 9194893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:31:10+00:00 2026-06-17T21:31:10+00:00

printf is ouput is being destyoryed by a \n after I run scanf. I

  • 0

printf is ouput is being destyoryed by a “\n” after I run scanf. I am attempting to use.

scanf ("%*c");

to chomp the “\n” but its not working… here is the code

    printf("Enter char float int char:", char4, deci2, num2, char5);
    scanf ("%c %f %d %c", &char4, &deci2, &num2, &char5);
    scanf ("%*c");
    printf("You entered: '%c' %.3f %d '%c' " ,char4 ,deci2, num2, char5 );

and it outputs to

    Enter char int char float:a 5 a 5.5
    You entered: 'a' 5 'a' 5.500 
    Enter char float int char:a 5.5 6 b
    You entered: '
    ' 0.000 0 ''
  • 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-17T21:31:11+00:00Added an answer on June 17, 2026 at 9:31 pm

    The line

    scanf ("%c %f %d %c", &char4, &deci2, &num2, &char5);
    

    is picking up the stray newline left in the input buffer from your previous scanf call. You can work around that by putting a space in front of the first %c:

    scanf (" %c %f %d %c", &char4, &deci2, &num2, &char5);
    

    This will tell scanf to skip over any leading whitespace (blanks, newlines, tabs, etc.) before reading the next non-whitespace character.

    The line

    printf("Enter char float int char:", char4, deci2, num2, char5);
    

    is a bit of a head-scratcher; it won’t cause any problems (the excess arguments are evaluated, but otherwise ignored), but it looks wrong, and indicates some confusion.

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

Sidebar

Related Questions

Possible Duplicate: Why #include <stdio.h> is *not* required to use printf()? I am facing
is there a way to get with printf colored output? #!/usr/bin/perl use warnings; use
As everybody knows, you have limited precision when you use printf to output the
When I use printf/printf_s with two strings, I get the same output for both
int x; scanf(%d,&x); printf(%d,x); Input: . (just a period) Output: 4096 Why does it
Here is a program that models a tennis ball being thrown off the side
From now on, I think after fork() is being called, the local variable is
I've recently read this article on using printf and scanf in assembly: Meaning of
Here's the problem statement: The number 3797 has an interesting property. Being prime itself,
In Bash I can use printf to format a string output like this:- (Note

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.