积极答复者
倒序输出a-g这7个字符的问题

问题
-
// 倒序字符a-g.cpp : 定义控制台应用程序的入口点。
//abcdefg\0#include "stdafx.h"
#include<iostream>
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{int strlen1(char a[]);
char s[]="abcdefg";
char *p;
int n=strlen1(s);
cout<<"n="<<n<<endl;
for(p=s+n-1;p+1!=s;p--)
cout<<*p;
cout<<endl;return 0;
}
int strlen1(char a[])
{char *p=a;
int i=0;
while(a[i++]!='\0')
p++;
return p-a;
}问题是for(p=s+n-1;p+1!=s;p--)老师在vc++6.0说n=8,可这里n=7
for(p=s+n;p!=s;p--)还有为何这循环条件里p不能少了-1,不能少了+1,少时就输出括号里的错误值【 gfedcb】,360还杀毒报警?
希望斑竹回答
- 已编辑 h01123 2012年1月24日 14:15