A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FString%2Fchar_array_string</id>
		<title>C++/String/char array string - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FString%2Fchar_array_string"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/String/char_array_string&amp;action=history"/>
		<updated>2026-04-10T05:11:53Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/String/char_array_string&amp;diff=1394&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/String/char_array_string&amp;diff=1394&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/String/char_array_string&amp;diff=1395&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/String/char_array_string&amp;diff=1395&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:45Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Convert char array to upper case==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
struct Msg &lt;br /&gt;
{&lt;br /&gt;
  char message[256];&lt;br /&gt;
  void show_message(void) { cout &amp;lt;&amp;lt; message; }&lt;br /&gt;
};&lt;br /&gt;
struct UpperMsg &lt;br /&gt;
{&lt;br /&gt;
   char message[256];&lt;br /&gt;
   void show_message(void) { cout &amp;lt;&amp;lt; strupr(message); }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
   Msg book = { &amp;quot;B&amp;quot; };&lt;br /&gt;
   UpperMsg book_upr = { &amp;quot;c&amp;quot; };&lt;br /&gt;
   book.show_message();&lt;br /&gt;
   book_upr.show_message();&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Count spaces, punctuation, digits, and letters.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main() {&lt;br /&gt;
  const char *str = &amp;quot;This is a test. 1 2 3 4 5&amp;quot;;&lt;br /&gt;
  int letters = 0, spaces = 0, punct = 0, digits = 0;&lt;br /&gt;
  cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; endl;&lt;br /&gt;
  while(*str) {&lt;br /&gt;
    if(isalpha(*str)) &lt;br /&gt;
       ++letters;&lt;br /&gt;
    else if(isspace(*str)) &lt;br /&gt;
       ++spaces;&lt;br /&gt;
    else if(ispunct(*str)) &lt;br /&gt;
       ++punct;&lt;br /&gt;
    else if(isdigit(*str)) &lt;br /&gt;
       ++digits;&lt;br /&gt;
    ++str;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Letters: &amp;quot; &amp;lt;&amp;lt; letters &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Digits: &amp;quot; &amp;lt;&amp;lt; digits &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Spaces: &amp;quot; &amp;lt;&amp;lt; spaces &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Punctuation: &amp;quot; &amp;lt;&amp;lt; punct &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrate the basic null-terminated string functions.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main() {&lt;br /&gt;
  char strA[7] = &amp;quot;U&amp;quot;;&lt;br /&gt;
  char strB[5] = &amp;quot;D&amp;quot;;&lt;br /&gt;
  char strC[5] = &amp;quot;L&amp;quot;;&lt;br /&gt;
  char strD[6] = &amp;quot;R&amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Here are the strings: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strA: &amp;quot; &amp;lt;&amp;lt; strA &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strB: &amp;quot; &amp;lt;&amp;lt; strB &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strC: &amp;quot; &amp;lt;&amp;lt; strC &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strD: &amp;quot; &amp;lt;&amp;lt; strD &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Length of strA is &amp;quot; &amp;lt;&amp;lt; strlen(strA) &amp;lt;&amp;lt; endl;&lt;br /&gt;
  strcat(strA, strB);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strA after concatenation: &amp;quot; &amp;lt;&amp;lt; strA &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Length of strA is now &amp;quot; &amp;lt;&amp;lt; strlen(strA) &amp;lt;&amp;lt; endl;&lt;br /&gt;
  strcpy(strB, strC);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;strB now holds: &amp;quot; &amp;lt;&amp;lt; strB &amp;lt;&amp;lt; endl;&lt;br /&gt;
  if(!strcmp(strB, strC))&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;strB is equal to strC\n&amp;quot;;&lt;br /&gt;
  int result = strcmp(strC, strD);&lt;br /&gt;
  if(!result)&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;strC is equal to strD\n&amp;quot;;&lt;br /&gt;
  else if(result &amp;lt; 0)&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;strC is less than strD\n&amp;quot;;&lt;br /&gt;
  else if(result &amp;gt; 0)&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;strC is greater than strD\n&amp;quot;;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Filling an Array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
    char buffer[80] = {&amp;quot;\0&amp;quot;};&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Enter the string: &amp;quot;;&lt;br /&gt;
    std::cin &amp;gt;&amp;gt; buffer;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Here&amp;quot;s the buffer: &amp;quot; &amp;lt;&amp;lt; buffer &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Get the string length==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
#include &amp;lt;string.h&amp;gt;  &lt;br /&gt;
using namespace std;&lt;br /&gt;
main(void)  &lt;br /&gt;
{  &lt;br /&gt;
  int i;  &lt;br /&gt;
  i = 10;  &lt;br /&gt;
     &lt;br /&gt;
  int j = 100;&lt;br /&gt;
     &lt;br /&gt;
  cout &amp;lt;&amp;lt; i*j &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;  &lt;br /&gt;
     &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter a string: &amp;quot;;  &lt;br /&gt;
  char str[80];  &lt;br /&gt;
  cin &amp;gt;&amp;gt; str;  &lt;br /&gt;
     &lt;br /&gt;
  // display the string in reverse order  &lt;br /&gt;
  int k;  &lt;br /&gt;
  k = strlen(str);  &lt;br /&gt;
  k--;  &lt;br /&gt;
  while(k&amp;gt;=0) {  &lt;br /&gt;
    cout &amp;lt;&amp;lt; str[k];  &lt;br /&gt;
    k--;  &lt;br /&gt;
  }  &lt;br /&gt;
     &lt;br /&gt;
  return 0;  &lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Operator pointer==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Book {&lt;br /&gt;
  public:&lt;br /&gt;
    Book(char *title, char *publisher, char *author);&lt;br /&gt;
    void show_book(void) { &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Book: &amp;quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; &amp;quot; by &amp;quot; &amp;lt;&amp;lt;&lt;br /&gt;
        author &amp;lt;&amp;lt; &amp;quot; Publisher: &amp;quot; &amp;lt;&amp;lt; publisher &amp;lt;&amp;lt; endl; &lt;br /&gt;
  };&lt;br /&gt;
    operator char *();&lt;br /&gt;
   &lt;br /&gt;
  private:&lt;br /&gt;
    char title[64];&lt;br /&gt;
    char author[64];&lt;br /&gt;
    char publisher[64];&lt;br /&gt;
};&lt;br /&gt;
Book::Book(char *title, char *publisher, char *author)&lt;br /&gt;
{&lt;br /&gt;
   strcpy(Book::title, title);&lt;br /&gt;
   strcpy(Book::publisher, publisher);&lt;br /&gt;
   strcpy(Book::author, author);&lt;br /&gt;
}&lt;br /&gt;
Book::operator char *(void)&lt;br /&gt;
{&lt;br /&gt;
   char *ptr = new char[256]; &lt;br /&gt;
   &lt;br /&gt;
   return(strcpy(ptr, title)); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
   Book myBook(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;,&amp;quot;C&amp;quot;);&lt;br /&gt;
   &lt;br /&gt;
   char *title;&lt;br /&gt;
   title = myBook;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;The book&amp;quot;s title is &amp;quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use strlen() to get the length of a char array buffer==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char buffer[80];&lt;br /&gt;
   do&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Enter a string up to 80 characters: &amp;quot;;&lt;br /&gt;
      cin.getline(buffer,80);&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Your string is &amp;quot; &amp;lt;&amp;lt; strlen(buffer);&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot; characters long.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }while (strlen(buffer));&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using atoi() function==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char buffer[80];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a number: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; buffer;&lt;br /&gt;
   int number;&lt;br /&gt;
   number = atoi(buffer);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Here&amp;quot;s the number: &amp;quot; &amp;lt;&amp;lt; number &amp;lt;&amp;lt; endl;&lt;br /&gt;
   int sum = atoi(buffer) + 5;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Here&amp;quot;s sum: &amp;quot; &amp;lt;&amp;lt; sum &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using strcat() and strncat().==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char stringOne[255];&lt;br /&gt;
   char stringTwo[255];&lt;br /&gt;
   stringOne[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   stringTwo[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a  string: &amp;quot;;&lt;br /&gt;
   cin.getline(stringOne,80);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a second string: &amp;quot;;&lt;br /&gt;
   cin.getline(stringTwo,80);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   strcat(stringOne,&amp;quot; &amp;quot;);&lt;br /&gt;
   strncat(stringOne,stringTwo,10);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using strcpy and string terminator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char stringOne[80];&lt;br /&gt;
   char stringTwo[80];&lt;br /&gt;
   stringOne[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   stringTwo[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a string: &amp;quot;;&lt;br /&gt;
   cin.getline(stringOne,80);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nString One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;copying...&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   strcpy(stringTwo,stringOne);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nString One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nDone &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using strcpy() to assign value from one char array to another char array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char String1[] = &amp;quot;this is a test&amp;quot;;&lt;br /&gt;
   char String2[80] = {&amp;quot;\0&amp;quot;};&lt;br /&gt;
   strcpy(String2,String1);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String1: &amp;quot; &amp;lt;&amp;lt; String1 &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String2: &amp;quot; &amp;lt;&amp;lt; String2 &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using strncpy() and string terminator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char stringOne[80];&lt;br /&gt;
   char stringTwo[10];&lt;br /&gt;
   char stringThree[80];&lt;br /&gt;
   stringOne[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   stringTwo[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   stringThree[0]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Three: &amp;quot; &amp;lt;&amp;lt; stringThree &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a long string: &amp;quot;;&lt;br /&gt;
   cin.getline(stringOne,80);&lt;br /&gt;
   strcpy(stringThree,stringOne);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nString One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Three: &amp;quot; &amp;lt;&amp;lt; stringThree &amp;lt;&amp;lt; endl;&lt;br /&gt;
   strncpy(stringTwo,stringOne,9);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nString One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Three: &amp;quot; &amp;lt;&amp;lt; stringThree &amp;lt;&amp;lt; endl;&lt;br /&gt;
   stringTwo[9]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nString One: &amp;quot; &amp;lt;&amp;lt; stringOne &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Two: &amp;quot; &amp;lt;&amp;lt; stringTwo &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String Three: &amp;quot; &amp;lt;&amp;lt; stringThree &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nDone.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using strncpy() to assign one char array to another char array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    const int MaxLength = 80;&lt;br /&gt;
    char String1[] = &amp;quot;this is a test&amp;quot;;&lt;br /&gt;
    char String2[MaxLength+1] = {&amp;quot;\0&amp;quot;};&lt;br /&gt;
    strncpy(String2, String1, MaxLength);    &lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;String1: &amp;quot; &amp;lt;&amp;lt; String1 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;String2: &amp;quot; &amp;lt;&amp;lt; String2 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>