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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:51:56+00:00 2026-06-13T08:51:56+00:00

Here is my code: #include <stdio.h> void scan(int* i) { int t=0; char c;

  • 0

Here is my code:

#include <stdio.h>

void scan(int* i)
{
    int t=0;
    char c;
    bool negative=false;
    c=getchar_unlocked();
    while(c<'0'&&c>'9')
    {
        if(c=='-')
            negative=true;
        c=getchar_unlocked();
    }
    while(c>'0'&&c<'9')
    {
        t=(t<<3)+(t<<1)+c-'0';
        c=getchar_unlocked();
    }
    if(negative)
        t=~(t-1); //negative
    *i=t;
}

int main(int argc, char const *argv[])
{
    int i;
    scan(&i);
    return 0;
}

I know that the function defined here as scan is faster than scanf and is very useful on programming competitions. But for some reason this code is not working on Windows and is working on Linux. What do I do to get it working on Windows? I am using the g++ compiler from Dev-C++.

  • 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-13T08:51:57+00:00Added an answer on June 13, 2026 at 8:51 am

    getchar_unlocked is not a C or C++ standard function and therefore it’s no surprise that it doesn’t work on Windows. It is a POSIX standard I think, but Windows compilers don’t support all POSIX functions.

    If you replaced getchar_unlocked with getchar, it would kind of work, although the algorithm doesn’t seem quite right.

    You could do this with conditional compilation, like this for instance

    #ifdef _WINDOWS
    // no getchar_unlocked on Windows so just call getchar
    inline int getchar_unlocked() { return getchar(); }
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here is my code: #include <stdio.h> #include <string.h> #include <errno.h> int cmp(const void *a,
Here is my code: #include <stdio.h> #include <unistd.h> static volatile int t=0; int main(void){
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here's my code: #include <stdio.h> typedef struct node_struct { int data; struct node_struct *next;
Consider the code : #include <stdio.h> class Base { public: virtual void gogo(int a){
Here's my code: #include<stdio.h> void main() { FILE *fp; fp=fopen(text.txt,r); if(fp==NULL) printf(ahaha); struct karan{
Here is the code #include<stdio.h> #include<sys/types.h> #include<stdlib.h> #include<pthread.h> typedef struct std_thread { char name[20];
I am going to paste here my code and errors: #include stdio.h #include winsock2.h
Here is my code: #include <stdio.h> #include <string.h> #include <windows.h> #include <tchar.h> #define MAX_KEY_LENGTH

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.