Comments

Monday, October 8, 2012

Copy Character Array using Pointers

Posted by at 2:23 PM Read our previous post


intialize a char pointer with some text declare an array variable of type
char.copy the statement in char pointer variable to the array variable.


Source code

#include <iostream>
using namespace std;
void cpystr(char *instr, char *outstr);
void cpystr(char *instr, char *outstr)
{
while( *(outstr++) = *(instr++) );
}
void main()
{
char in[]={"This is new era"};
char out[16],*pointer,*pointer1;
pointer =in;
pointer1 = out;
cpystr(pointer, pointer1);
cout << "in: " << in << endl;
cout << "out: " << out << endl;
}


Output
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template