⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg2_1.cpp

📁 经典数据结构书籍 数据结构C++语言描述 的源代码 很难找的哦
💻 CPP
字号:
#include <iostream.h>
#include <string.h>

// reverse first and last name and separate them
// with a comma. copy result to newName.
void ReverseName(char *name, char *newName)
{
    char *p;
        
    // search for first blank in name and replace with NULL char
    p = strchr(name,' ');       
    *p = 0;
    
    // copy last name to newName, append ", " and
    // concatenate first name  
    strcpy(newName,p+1);
    strcat(newName,", ");
    strcat(newName,name);
    
    // replace the NULL char with the original blank
    *p = ' ';
}
    
void main(void)
{
    char name[32], newName[32];
    int  i;
    
    // read and process three names
    for (i = 0; i < 3; i++)
    {
        cin.getline (name,32,'\n');
        ReverseName(name,newName);
        cout << "Reversed name: " << newName << endl << endl;
    }
}

/*
<Run of Program 2.1>

Abraham Lincoln
Reversed Name: Lincoln, Abraham

Debbie Rogers
Reversed Name: Rogers, Debbie

Jim Brady
Reversed Name: Brady, Jim
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -