String to Array of Char Conversion in C++

This is a simple program for beginners to convert a string into array of char in C++ program. To convert a string into array of char strcpy function is used which exist in stdio.h library.

Source Code

#include<iostream>
#include<string.h>
#include <stdio.h>
using namespace std;
int main ()
{
 cout<<"\t \t \t LEP Tutorials \n \n \n ";
 char words [100];
 char choice;
 string sentence = "WELCOME TO C++ Tutorials \n";
 cout<<sentence<<endl;
 cout<<"Do You Want to Convert it in Array of Char ? Y/N \n";
 cin>>choice;
 if ((choice =='Y') ||(choice=='y'))
 {
       strcpy(words, sentence.c_str());
       for (int i=0;i<strlen(words);i++)
    {
     cout<<words[i];
    }
}
}

Output of the Program

String to Array of Char Conversion in C++
String to Array of Char Conversion in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment