编译没有错误,但是执行后系统提示错误,请帮忙看一下,谢谢
#include <windows.h>
#include <stdio.h>
#define ENV_VAR_STRING_COUNT (sizeof(envVarStrings)/sizeof(TCHAR*))
#define INFO_BUFFER_SIZE 32767
main()
{
char *File(char (*get));
char *get_path;
printf("%s\n",*get_path );
}
char *File(char (*get))
{
char destination[25];
char *p;
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
GetSystemDirectory( infoBuf, INFO_BUFFER_SIZE );
char *c = "\\cyc.exe";
strcpy(destination, infoBuf);
strcat(destination, c);
get= destination; //个人感觉这里错误。 指针指向了数组。这是我的想法,但是不知道是这里错误么。我是菜鸟刚学的菜鸟,所以请老师帮助一下
return (get);
}
[解决办法]
#include <windows.h > #include <stdio.h > #define ENV_VAR_STRING_COUNT (sizeof(envVarStrings)/sizeof(TCHAR*)) #define INFO_BUFFER_SIZE 32767 char *File(char (*get));main() { char *get_path; //这里get_path没有初始化,看你的程序,应该是=File的返回值 printf("%s\n",*get_path ); } char *File(char (*get)) { char destination[25]; char *p; TCHAR infoBuf[INFO_BUFFER_SIZE]; DWORD bufCharCount = INFO_BUFFER_SIZE; GetSystemDirectory( infoBuf, INFO_BUFFER_SIZE ); char *c = "\\cyc.exe"; strcpy(destination, infoBuf); strcat(destination, c); get= destination; //这里修改了get的值,一般对于形参建议不进行修改,用一个新的变量进行赋值 return (get); }
[解决办法]
#include <windows.h>#include <stdio.h> //#define ENV_VAR_STRING_COUNT (sizeof(envVarStrings)/sizeof(TCHAR*))char *File(char (*get));void main() { char *get_path = new char[MAX_PATH]; memset(get_path,0,MAX_PATH); File(get_path); printf("%s\n",get_path );//printf("%s\n",*get_path ); delete []get_path;} char *File(char (*get)){ //char destination[25]; //char *p; //TCHAR infoBuf[INFO_BUFFER_SIZE]; DWORD bufCharCount = MAX_PATH + 1; GetSystemDirectory( get, MAX_PATH + 1 ); char *c = "\\cyc.exe"; //strcpy(destination, infoBuf); strcat(get, c); //get= destination; //个人感觉这里错误。 指针指向了数组。这是我的想法,但是不知道是这里错误么。我是菜鸟刚学的菜鸟,所以请老师帮助一下 return (get); }