pr0803.cpp

来自「practice c++, it is from the book http:/」· C++ 代码 · 共 26 行

CPP
26
字号
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Problem 8.3 on page 202
//  The strncat() function

#include <iostream>
using namespace std;
char* Strncat(char*, const char*, size_t);

int main()
{ const char* s = "ABCDEFG";
  char* ss = "ZZZZZZZZZZ";
  cout << " s = [" << s << "], ss = [" << ss << "]\n";
  Strncat(ss,s,2);
  cout << " s = [" << s << "], ss = [" << ss << "]\n";
}

char* Strncat(char* s1, const char* s2, size_t n)
{ char* end; for (end=s1; *end; end++)  // find end of s1
    ;
  char* p; for (p=s2; *p && p-s2<n; )
    *end++ = *p++;	
  *end = '\0';
  return s1;
}

⌨️ 快捷键说明

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