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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:51:54+00:00 2026-06-09T17:51:54+00:00

Can I use scanf(…) as argument to a function ? Like this: printInteger(scanf(….)); Can

  • 0

Can I use scanf(...) as argument to a function ?
Like this:

printInteger(scanf(....));

Can I use scanf to attribute the value that I read to some variable ?
Like this:

n = scanf(...);

p.s.: Here I’m explaining why I’m asking this.

This question can be a little weird I know, but I’m working in a project, which is developing a compiler that takes some language as input and then compile to C.

For example, this is my language, let’s call ‘stackoverflow’ 😉

proc printInteger(integer k)
    integer i;
        begin
            for i = 1 to k do
                print i;
        end

proc main()
    integer n, i;
    boolean ok;
    begin
        printInteger(getInteger);
        n = getInteger;
        ok = true;
        while i < n do
            begin
                print i;
                i = i + 1;
            end
        if ok then print 1; else print 0;
    end

I won’t get deeper in the language, but notice that getInteger means that I would like to do a scanf(...), what I mean is, when appears getInteger I would like to compile as scanf(...), so that’s why I would like to know some ways to use scanf(...).

  • 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-09T17:51:55+00:00Added an answer on June 9, 2026 at 5:51 pm

    Can I use scanf(…) as argument to a function ? Like this:

    printInteger(scanf(….));

    Can I use scanf to attribute the value that I read to some variable ? Like this:

    n = scanf(…);

    You can use scanf as an argument to a function, but the real answer to both questions is no: scanf doesn’t return any data scanned, it returns the number of items successfully scanned – or EOF if the end-of-input is reached before any successful scanning. You only get access to the items scanned using the pointers that you pass as scanf arguments to receive the values. So while you can pass scanf as an argument to a function, it won’t do what you seem to want.

    If you want to implement the getInteger operation in your language, in C, it’s hard to make suggestions since only you know how this language/operation should work. Just using scanf, the implementation would look something like this:

    int nextInt;
    int numScanned = scanf("%d", &nextInt);
    
    if (numScanned < 1)
        handleError();
    return nextInt;
    

    But if you’re doing general parsing for your language, then using scanf is a bad idea: you’ll soon run into problems with the limitations of scanf, and you’re not going to be able to anticipate all of the input types unless your language is really simple, simpler than the example that you’ve included.

    To do this properly, find a good lex library for C. This will prevent a lot of headaches. Otherwise, if you must do the lexing yourself, start looking over fgets, get a line at a time from your input, and do the tokenizing yourself.

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

Sidebar

Related Questions

How can I use a variable to specify the field length when using scanf.
A[50][5000]; for(i=0;i<50;++i) scanf(%[\n],A[i]); %[^\n] usage and meaning of it and can i use that
How can I use information from array that will be passed from function? #include
Is there any magic tools i can use to scan source code that was
I can use this maven plugin maven-jaxb-plugin to generate Java Classes from XSD file.
We can use solr range query like: http://localhost:8983/solr/select?q=queryStr&fq=x:[10 TO 100] AND y:[20 TO 300]
You can use the Filter property of a BindingSource to do SQL like filtering.
I've read that system(pause) is slow and not advisable to use. Is there any
Unfortunately in this log I have there are some strings with that notation (1.00e4),
Some background: If I wanted to use for, for instance, scanf() to convert a

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.