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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:42:37+00:00 2026-06-09T12:42:37+00:00

#include <stdio.h> int main(){ int l,m,q,j; char option; scanf(%d,&q); printf(%d\n,q); for(j=0;j<q;j++){ scanf(%c %d %d,&option,&l,&m);

  • 0
#include <stdio.h>

int main(){
    int l,m,q,j;
    char option;
    scanf("%d",&q);
    printf("%d\n",q);
    for(j=0;j<q;j++){
        scanf("%c %d %d",&option,&l,&m);
        printf("%c %d %d",option,l,m);
    }
    return 0;
}

Output:

3(Input)
3
C 1 4(Input)

 0 -374066224C 1 4

What is wrong with the above code? It is not giving the expected output.

  • 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-09T12:42:38+00:00Added an answer on June 9, 2026 at 12:42 pm

    There is still a newline character in the input stream from the initial scanf() (and subsequent scanf()s): this will be assigned to option and the subsequent int assignments will fail as C is not an int, meaning l and m are uninitialised int variables.

    To skip it add a leading space character to the format specifier of the scanf() within the for loop:

    scanf(" %c %d %d",&option,&l,&m);
        /* ^ */
    

    The return value of scanf() is the number of successful assignments made: check it to ensure 3 assignments are made.

    if (3 == scanf(" %c %d %d",&option,&l,&m))
    {
        /* Valid input. */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
#include <stdio.h> int main() { char temp[1024]; if(getchar() != 'y') { printf(no options\n); return
#include<stdio.h> int main() { char *s[] = { knowledge,is,power}; char **p; p = s;
#include <stdio.h> int main() { char read = ' '; while ((read = getchar())
#include<stdio.h> int main() { char a[5]=hello; puts(a); //prints hello } Why does the code
#include<stdio.h> int a[100]; int main(){ char UserName[100]; char *n=UserName; char *q=NULL; char Serial[200]; q=Serial;
Today I found the following: #include <stdio.h> int main(){ char x = 255; int
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
hi can anybody tell me the error in this? #include<stdio.h> int main() { char
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);

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.