programming serial arduino with visual C++

Hi all
I try to read sensor analog from serial using Visual studio C++ 2010.
my arduino program :

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}

void loop() {
  char request[1];
  if(Serial.available()){
    request[0]=Serial.read();
    Serial.print(analogRead(atoi(request)));
    Serial.print("\n\r");
  };
  delay(2);                     
}

my Serial C++ program :

#include <windows.h>
#include "stdafx.h"
#include "SerialClass.h"

char buffer[20];
char buf0[200];


int _tmain(int argc, _TCHAR* argv[])
{
   Serial oSerial("COM6:");
   
   while(1){
	sprintf_s(buffer,"0");    
        oSerial.WriteData(buffer,1); 
	Sleep(1000);
	oSerial.ReadData(buf0,4);
	printf("Sensor 0: %s \n",buf0);
	Sleep(1000); }
}

I put 5V on sensor 0 but the result is not stable:

sensor 0 :
sensor 0 : 10230
sensor 0:
100
sensor 0: 23
0
sensor 0: 10230

and so on,

I think there is no wrong with arduino side because when I use serial monitor on arduino it seems alright.
Any suggestion?

    oSerial.ReadData(buf0,4);

Look at the documentation. What does this function do if there are more than 4 characters to read? More importantly, what does it do if there are less than 4 characters?

You are actually sending 6 characters, you know.

  char request[1];
  if(Serial.available()){
    request[0]=Serial.read();
    Serial.print(analogRead(atoi(request)));

This is not good coding. The array buffer has room for one character. The atoi() function expects a NULL terminated array of chars. Your array of chars is NOT null terminated. There is no telling where in memory the next NULL or non-numeric value is, so the return value from atoi() is NOT predictable.

Being lucky is good. Being correct is even better. Make that array larger and add a NULL in the 2nd position.

Thank you Pauls, I are right after I change to :

oSerial.ReadData(buf0,6);

it seems all right for data less than 4 digit after 4 digit let say 1023 the display is

sensor 0:1023 (here there are 18 squares)

what the meaning of those squares?