用一重循环实现
给出一个字符数组:char ch[] = {'a', 'b', 'c', '\0'};
如何产生如下输出:
abc
bc
c
注意:用一重循环。
程序代码:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
char ch[] = {'a', 'b', 'c', '\0'};
char buffer[255];
for (int i=0; i!=3; ++i)
{
strncpy(buffer,&ch[i],4-i);
cout<<buffer<<endl;
}
system("pause");
return 0;
}