积极答复者
程序没有输出预期的结果:反向输出字符串

问题
-
#include <stdio.h>
char* main()
{
int n=0;
int c=0;
int i;
char bbc[80]={0};
printf("Please input a string:\n");
scanf("%s",bbc);
char temp[200]="0";
int length = strlen(bbc);
for(i = 0; i < length+1; i++)
{
temp[i] = bbc[length - i];
} //end for
temp[i] = '\n';
printf("%s",temp);
return temp ;
}
答案
-
#include "stdafx.h" #include <iostream> using namespace std; int main() { int n=0; int c=0; int i; char bbc[80]={0}; printf("Please input a string:\n"); gets(bbc); char temp[200]= {0}; int length = strlen(bbc); for(i = 0; i < length; i++) { temp[i] = bbc[length - 1 - i]; } //end for temp[i] = '\n'; printf("%s",temp); return 0 ; } 不过要注意数组溢出的问题,如果输入的字符串超长~
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已建议为答案 i1friend 2012年7月19日 10:35
- 已标记为答案 Elegentin XieModerator 2012年7月31日 6:48
-
不好意思,我说的不是字符串,是这个API GetExitCodeProcess
麻烦把正确答案设为解答。
- 已标记为答案 Elegentin XieModerator 2012年7月31日 6:48
全部回复
-
#include "stdafx.h" #include <iostream> using namespace std; int main() { int n=0; int c=0; int i; char bbc[80]={0}; printf("Please input a string:\n"); gets(bbc); char temp[200]= {0}; int length = strlen(bbc); for(i = 0; i < length; i++) { temp[i] = bbc[length - 1 - i]; } //end for temp[i] = '\n'; printf("%s",temp); return 0 ; } 不过要注意数组溢出的问题,如果输入的字符串超长~
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已建议为答案 i1friend 2012年7月19日 10:35
- 已标记为答案 Elegentin XieModerator 2012年7月31日 6:48
-
可以取得上面的返回值吗? int是可以的,char不知道行不行
#include <Windows.h>
//#include <iostream>
#include <stdio.h>int main(int argc, TCHAR* argv[])
{
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi = {0};
TCHAR szApp[MAX_PATH] = {TEXT("C:\\1\\process\\m1.exe")};
if(CreateProcess(szApp, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, 4000);
DWORD dwRet = 0;
//hProcess=GetExitCodeProcess(pi.hProcess, &dwRet)
if(GetExitCodeProcess(pi.hProcess, &dwRet))
{
//printf("return value= : %d characters.\n",dwRet);
printf("return value= : %s characters.\n",dwRet);
//printf<<"return value = "<<dwRet<<endl;
}
TerminateProcess(pi.hProcess,1);CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
else
{
//cout<<"error: "<<GetLastError()<<endl;
return;
}
return 0;
}- 已编辑 Honny_yeyh 2012年7月19日 3:49
-
int是api的返回值
麻烦把正确答案设为解答。
- 已标记为答案 Honny_yeyh 2012年7月25日 9:08
- 取消答案标记 Honny_yeyh 2012年7月25日 9:09
-
int是api的返回值
下面这个INT可以
麻烦把正确答案设为解答。
int main()
{
int n=0;
int c=0;
int i;
char bbc[80]={0};
printf("Please input a string:\n");
gets(bbc);
char temp[200]= {0};
int length = strlen(bbc);
for(i = 0; i < length; i++)
{
temp[i] = bbc[length - 1 - i];
} //end for
temp[i] = '\n';
printf("%s",temp);
return 0 ;
}
-
不好意思,我说的不是字符串,是这个API GetExitCodeProcess
麻烦把正确答案设为解答。
- 已标记为答案 Elegentin XieModerator 2012年7月31日 6:48