用一重循环实现
给出一个字符数组:char ch[] = {'a', 'b', 'c', '\0'};
如何产生如下输出:
abc
bc
c
注意:用一重循环。
2008-03-05 15:47
程序代码:
#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;
}
2008-03-05 17:07
2008-03-05 20:06
2008-03-05 20:10
程序代码:#include <iostream>
using namespace std;
int main(){
char *st = "abc";
for(int i = 0; i < strlen(st); i++)
cout << st + i << endl;
getchar();
return 0;
}
2008-03-06 10:16
程序代码:int main(){
char *str = "anything";
while (*str)
cout << str++ << endl;
return 0;
}

2008-03-06 20:39