Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to pass data to scanf() without entering in the console?

How to pass data to scanf() without entering in the console?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cppcook
    wrote on last edited by
    #1

    Hi Everybody, I need to run a command driven program in a MFC application. Then I include "WinExec("commandprogram param1 param2",SW_HIDE)" in the MFC application. The problem is the command driven program has a scanf() function, but I know the value needs to be entered and I don't want to input the value manually again. How can I pass the value to scanf() without inputing any value in the keyboard? I don't want to rewrite the function in the command driven program. Thank you very much. Gavin

    L J 2 Replies Last reply
    0
    • C cppcook

      Hi Everybody, I need to run a command driven program in a MFC application. Then I include "WinExec("commandprogram param1 param2",SW_HIDE)" in the MFC application. The problem is the command driven program has a scanf() function, but I know the value needs to be entered and I don't want to input the value manually again. How can I pass the value to scanf() without inputing any value in the keyboard? I don't want to rewrite the function in the command driven program. Thank you very much. Gavin

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      I don't know what WinExec supports but some spawning functions support attaching to the child process IO streams so that might work for you.

      1 Reply Last reply
      0
      • C cppcook

        Hi Everybody, I need to run a command driven program in a MFC application. Then I include "WinExec("commandprogram param1 param2",SW_HIDE)" in the MFC application. The problem is the command driven program has a scanf() function, but I know the value needs to be entered and I don't want to input the value manually again. How can I pass the value to scanf() without inputing any value in the keyboard? I don't want to rewrite the function in the command driven program. Thank you very much. Gavin

        J Offline
        J Offline
        Jun Du
        wrote on last edited by
        #3

        Have you tried I/O redirection: "commandprogram param1 param2 < input_string" in your WinExec call? Best, Jun

        C 1 Reply Last reply
        0
        • J Jun Du

          Have you tried I/O redirection: "commandprogram param1 param2 < input_string" in your WinExec call? Best, Jun

          C Offline
          C Offline
          cppcook
          wrote on last edited by
          #4

          Thanks Jun and led. Best, Gavin

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups