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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:33:05+00:00 2026-05-20T08:33:05+00:00

I am creating a console application for read and write. I have created my

  • 0

I am creating a console application for read and write. I have created my screen buffer for reading and writing using “CreateConsoleScreenBuffer”. I am to write to the console but unable to read the input from the user. I have added the code.

#include <windows.h>
#include <stdio.h>

#define BUFSIZE 4096
int main(void)
{
   CHAR chBuf[BUFSIZE];
   DWORD dwRead, dwWritten,dwFlags,fdwMode;
   HANDLE hWrite;
   WORD wOldColorAttrs,len;
   SECURITY_ATTRIBUTES saAttr;
   FILE *FD = NULL;
   FD = fopen ( "temp7.txt","w+");

   AllocConsole();
   LPSTR lpszPrompt1 = "********** Hi I am here ************* \n";

   hWrite = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CONSOLE_TEXTMODE_BUFFER,NULL);

   SetConsoleActiveScreenBuffer(hWrite);

   GetConsoleMode(hWrite,&dwFlags);

   fdwMode = dwFlags & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
   if (!SetConsoleMode(hWrite, fdwMode))
   {
      MessageBox(NULL, TEXT("SetConsoleMode"), TEXT("Console Error"), MB_OK);
      return 1;
   }

   fprintf(FD," ********** Flag for Get Console is %d ************ \n",dwFlags);

   if ( WriteConsole(hWrite,lpszPrompt1,strlen(lpszPrompt1),len,NULL)!= 0)
   {
    fprintf(FD," ********** Buffer Written %d and %d ************* \n",GetLastError(),hWrite);
    MessageBox(NULL, TEXT("SetConsoleMode"), TEXT("Write Error"), MB_OK);
        return 1;
   }
   for (;;)
   {
    if ( ReadFile(hWrite,chBuf,255,&dwRead,NULL)!= 0 )    // not overlapped
    {
       fprintf(FD," ********** Error Receiving User Buffer %d and %d ************* \n",GetLastError(),hWrite);
       break;
    }
    fprintf(FD," ********** Following is the Buffer (%d) Received from user ************* \n",dwRead);
    fprintf(FD," %s", chBuf);
    if( chBuf[0]== 'q')
    {
        fprintf(FD," ********** User Pressed Quit************* \n");
        break;
    }

    chBuf[0]='\0';
   }
   getch();
   return 0;
}

Following is the output:

 ********** Flag for Get Console is 3 ************ 
 ********** Following is the Buffer (0) Received from user ************* 
 # ********** Following is the Buffer (0) Received from user ************* 

Please help

~ Johnnie

  • 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-05-20T08:33:05+00:00Added an answer on May 20, 2026 at 8:33 am

    Thanks for the inputs. I have found out the Error. CreateConsoleScreenBuffer Can be used for output buffers. In addition, windows provides a way to create a file with CONIN$ and cONOUT$ which is nothing but the console input and output buffer files. This buffer will be of process console’s even if standard In and OUT are redirected.

     hRead=CreateFile("CONIN$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
     hWrite=CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
    

    Regards
    Johnnie

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

Sidebar

Related Questions

I have a long-running console-based application Sender that sends simple text to STDOUT using
I am creating a video frame output program in a c++ console application using
I'm creating a C# application, could be WinForm, but preferably console application, which needs
I have simple console application project for live video streaming using cross-platform libs on
I am using Visual Studio 2008 Express and I tried creating a simple console
When creating a web application, and lets say you have a User object denoting
I'm writing C# application which saves picture box screen to JPEG files. One thread
I am creating a web application using zkoss 5.0.4, Spring 3.0.3, Hibernate 3, and
I am creating a small console app that needs a progress bar. Something like...
I have to create an app that will read in some info from 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.