Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Character Pointer Usng As String

Friday, July 1, 2011

#include<iostream.h>
#include <conio.h>

int main(){
   const int aSize=25;
   char arr[aSize];
   char* pChar;
   int   i = 0;
   int   nameSize;
  
   pChar = arr;
   cout << "Enter a name: ";
  
  for (i=0; i<aSize; i++){
     *(pChar+i)=getch();

     // --- If Enter is pressed, stop copying and break out of the for loop
     if (arr[i] == '\r'){
        cout << endl;
        nameSize=i;    // storing the size of the name
        break;
     } // end if
     cout << arr[i];
  }  // end for - Array arr
  
  // Displaying Array
  cout << endl;
  for (i=0; i<nameSize; i++)
      cout << arr[i];
     
return 0;
} // end main()