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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:12:18+00:00 2026-06-16T07:12:18+00:00

i am a learner of ‘C’ and written a code, but after i compile

  • 0

i am a learner of ‘C’ and written a code, but after i compile it, shows a Debug Error message, here is the code:

#include<stdio.h>
void main()
{
    int n,i=1;
    char c;
    printf("Enter Charecter:\t");
    scanf("%s",&c);
    printf("Repeat Time\t");
    scanf("%d",&n);
    n=n;
    while (i <= n)
    {
        printf("%c",c);
        i++;
    }
}

Pls tell me why this happens and how to solve it

  • 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-16T07:12:19+00:00Added an answer on June 16, 2026 at 7:12 am

    I’m not sure you understood the answer to your other question: Odd loop does not work using %c

    These format specifiers are each used for a specific job.

    If you want to get a:

    • character from stdin use %c.
    • string (a bunch of characters) use %s.
    • integer use %d.

    This code:

    char c;
    printf("Enter Character:\t");
    scanf("%c",&c);
    

    Will read 1 character from stdin and will leave a newline ('\n') character there. So let’s say the user entered the letter A in the stdin buffer you have:

    A\n
    

    The scanf() will pull 'A' and store it in your char c and will leave the newline character. Next it will ask for your int and the user might input 5. stdin now has:

    \n5
    

    The scanf() will take 5 and place it in int n. If you want to consume that ‘\n’ there are a number of options, one would be:

    char c;
    printf("Enter Character:\t");
    scanf("%c",&c);  // This gets the 'A' and stores it in c
    getchar();       // This gets the \n and trashes it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Idle pondering from a Scala learner perhaps, but ... in my tinkerings I've written
A learner here. This has to be esasy but I cannot figure it out.
i'am a learner so i need still experience and i have many questions, but
I am a JavaScript learner and have been researching this matter, but with no
I'm new learner in CI and follow this CI simple login library (see here)
I'm a start learner about Ruby MetaProgramming. when practicing my code in irb, I
As a learner I like to look at lots of source code. Since I
I am new learner to WPF. here I got a question. I have a
I am a beginner python learner. I created this simple program but won't display
I am a new iphone learner. I have been reading tutorials but it seems

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.