Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Write C++ program to copy one string to another string using pointers

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    char strOrig[100], strCopy[100];
    char *origPtr, *copPtr;
    cout<<"Enter the string: ";
    gets(strOrig);
    origPtr = &strOrig[0];
    copPtr = &strCopy[0];
    while(*origPtr)
    {
        *copPtr = *origPtr;
        origPtr++;
        copPtr++;
    }
    *copPtr = '';
    cout<<"
Entered String: "<<strOrig;
    cout<<"
Copied String: "<<strCopy;
    cout<<endl;
    return 0;
}
Source by codescracker.com #
 
PREVIOUS NEXT
Tagged: #Write #program #copy #string #string #pointers
ADD COMMENT
Topic
Name
2+1 =