home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
string1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-29
|
1KB
|
46 lines
/*
C++ program that demonstrates C-style strings
*/
#include <iostream.h>
#include <string.h>
const unsigned MAX1 = 40;
const unsigned MAX2 = 80;
main()
{
char smallStr[MAX1+1];
char bigStr[MAX2+1];
char findChar, replChar;
cout << "Enter first string:\n";
cin.getline(bigStr, MAX2);
cout << "Enter second string:\n";
cin.getline(smallStr, MAX1);
cout << "String 1 has " << strlen(bigStr)
<< " characters\n";
cout << "String 2 has " << strlen(smallStr)
<< " characters\n";
// concatenate bigStr to smallStr
strcat(bigStr, smallStr);
cout << "Concatenated strings are:\n"
<< bigStr << "\n";
cout << "New string has " << strlen(bigStr)
<< " characters\n";
// get the search and replacement characters
cout << "Enter search character : ";
cin >> findChar;
cout << "Enter replacement character : ";
cin >> replChar;
// replace characters in string bigStr
for (unsigned i = 0; i < strlen(bigStr); i++)
if (bigStr[i] == findChar)
bigStr[i] = replChar;
// display the updated string bigStr
cout << "New string is:\n"
<< bigStr;
return 0;
}