首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

向函数传送指针也不能改变值?

2012-08-24 
向函数传递指针也不能改变值???C/C++ code#include string#include iostream#include occi.h#pragma

向函数传递指针也不能改变值???

C/C++ code
#include <string>#include <iostream>#include <occi.h>#pragma comment (lib, "oraocci11d.lib")using namespace std;int  SelectFrom (char *sqlexec);int main (){    char a[] = {"SELECT * FROM AAVARX"};    int b = SelectFrom (a);    cout<<a<<endl;    system ("pause");    return 0;}int  SelectFrom (char *sqlexec){    oracle::occi::Environment *env = oracle::occi::Environment::createEnvironment ();    oracle::occi::Connection *coon = env ->createConnection ("boss", "zzs880905", "shop");    oracle::occi::Statement *stmt = coon ->createStatement (sqlexec);    oracle::occi::ResultSet *res = stmt ->executeQuery ();    res ->next ();    sqlexec = (char *)malloc (strlen (res ->getString (1).c_str ()));    char *temp = strcpy (sqlexec, res ->getString (1).c_str ());    temp = strcat (sqlexec, res ->getString (2).c_str ());    coon ->terminateStatement (stmt);    env ->terminateConnection (coon);    oracle::occi::Environment::terminateEnvironment (env);    cout<<sqlexec<<endl;    return 0;}



[解决办法]

sqlexec = (char *)malloc (strlen (res ->getString (1).c_str ()));
// 这里改变了指针的地址,如果想从函数内部传递到函数外部,则要使用:
int SelectFrom (char **sqlexec)

你也可以注释掉malloc那句,但要保证a[]空间足够,否则容易溢出。

热点排行