Code Competitions

Coding competition
Showing posts with label pointer to store address of string. Show all posts
Showing posts with label pointer to store address of string. Show all posts

Thursday, 30 May 2013

program to enter string using pointer

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
    char *s,*p,a[20],i;
    i=0;
    s=&a[0];
    clrscr();
    while((*(a+i)=getchar())!='\n')
    {
        i++;
    }
    *(a+i)='\0';
    cout<<"entered string is accessed by array ";
    puts(a);
    cout<<"entered string is accessed by pointer ";
    puts(s);
    getch();
}