C Program Code For Copying the String Without STRCPY Function, Custom Made StringCopy Function

 /* The following C  program is used to copy a string in another array without using string.h function, strcpy(). The program asks for the input from user & the value is copied in the 2nd variable then displayed to user. */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void mystrcpy(char *d, char *s) 
//Function definition for string copy function
{
while(*s)
//While the source string is not encountered a NULL character
{
 *d=*s;
 s++;
 d++;
}
*d='\0';
}


int main()
{
  char s1[100];
  char s2[100];
  printf("\nEnter a string to copy: ");
  gets(s2);  
//User Input the string here
  mystrcpy(s1,s2);
  printf("\nThe Copied String is : ");
  puts(s2); 
//Copied string output shown here
  system("pause");
  return 0;
}


Screenshot:
C  Program Code For Copying the String Without STRCPY Function, Custom Made StringCopy Function

1 comment:

  1. #include

    using namespace std;


    template
    class LinkedList
    {
    private:
    struct Node
    {
    struct Node* prev;
    struct Node* next;
    T data;
    };
    struct Node* pNode;
    public:
    LinkedList();
    ~LinkedList();
    void append(T);
    void addAtBeg(T);
    void addAfter(int, T);
    void deleteNode(T);
    void display();
    void count();
    };

    template
    LinkedList::LinkedList()
    {
    pNode = NULL;
    }

    template
    LinkedList::~LinkedList()
    {
    struct Node* temp = pNode;

    while(pNode)
    {
    temp = pNode;
    pNode = pNode->next;
    delete temp;

    }
    }

    template
    void LinkedList::append(T data)
    {
    if(pNode == NULL)
    {
    pNode = new struct Node;
    pNode->next = NULL;
    pNode->prev = NULL;
    pNode->data = data;
    return;
    }
    else
    {
    struct Node* temp = pNode;
    while(temp->next != NULL)
    {
    temp = temp->next;
    }
    temp->next = new struct Node;
    temp->next->prev = temp;
    temp->next->next = NULL;
    temp->next->data = data;
    }
    }
    template
    void LinkedList::addAtBeg(T data)
    {

    if(pNode == NULL)
    {
    pNode = new struct Node;
    pNode->next = NULL;
    pNode->prev = NULL;
    pNode->data = data;
    return;
    }
    else
    {
    struct Node *temp = new struct Node;
    temp->next = pNode;
    pNode->prev = temp;
    temp->prev = NULL;
    temp->data = data;
    pNode = temp;
    }
    }

    template
    void LinkedList::addAfter(int position, T data)
    {
    cout << "Assumed will have some element and position is a valid position" <next;
    }
    struct Node *tempNode = new struct Node;
    tempNode->data = data;
    tempNode->prev = temp;
    tempNode->next = temp->next;
    temp->next = tempNode;
    }

    template
    void LinkedList::deleteNode(T data)
    {
    cout << "Here also not handled the condition, assumed data is in the link"<data != data)
    {
    temp = temp->next;
    }
    temp->prev->next = temp->next;
    temp->next->prev = temp->prev;
    delete temp;
    }

    template
    void LinkedList::display()
    {
    cout<< "Not checked all the condition,assumed that list have some element" <next;
    }
    cout << "Number of elements in the list = " << count << endl;
    }

    int main()
    {

    LinkedList *pLinkObj = new LinkedList();

    pLinkObj->append(2);
    pLinkObj->append(4);
    pLinkObj->append(6);
    pLinkObj->append(8);
    pLinkObj->append(10);

    cout << "======" << endl;
    pLinkObj->display();
    cout << "======" <addAtBeg(1);
    cout << "======" << endl;
    pLinkObj->display();
    cout << "======" <addAfter(4, 7);
    cout << "======" << endl;
    pLinkObj->display();
    cout << "======" <deleteNode(8);
    pLinkObj->display();

    pLinkObj->count();

    delete pLinkObj;
    return 0;
    }


    ReplyDelete