|
-
Jan 2nd, 2007, 01:48 AM
#1
Thread Starter
Junior Member
How to convert char * to char []?
Hai this is senthil...
i'm working in the field of VC++....
Now i'm trying to writing a string into a file which is fetched from the
mysql database....
i tried the following codings for the above process
i had tried to write a simple string into a file(any file such as xml,txt
or html)....
if we put .txt.. then the file automatically saving as txt..
But i dont know how to retrive a string from the Mysql database and
write that retrived string to a file
My codings are below...
--------------------------------------------------------------------
#include<stdio.h>
#include <mysql.h>
#include <conio.h>
#include <windows.h>
#include<string.h>
#define host "192.168.0.2"
#define username "root"
#define password ""
#define database "indesign"
void main()
{
MYSQL *conn;
conn = mysql_init(NULL);
mysql_real_connect(conn,host,username,password,dat abase,0,NULL,0);
MYSQL_RES *res_set;
MYSQL_ROW row;
mysql_query(conn,"SELECT text FROM sen1");
res_set = mysql_store_result(conn);
unsigned int numrows = mysql_num_rows(res_set);
//For Creating a file
HANDLE hFile;
DWORD wmWritten;
char strData[] = row[0];
hFile = CreateFile("C:\\test2.txt",GENERIC_READ|GENERIC_WR ITE,
FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NO RMAL,NULL);
while ((row = mysql_fetch_row(res_set)) != NULL)
{
WriteFile(hFile,strData,(DWORD)(sizeof(strData)),& wmWritten,NULL);
CloseHandle(hFile);
}
mysql_close(conn);
getch();
}
--------------------------------------------------------------------------
in row[0] i just put a string "senthil"...
But if there is no db connectivity the above program works
supervly... it creates xml, html, txt any type of files.
Now just i'm writing that string "senthil" which is retrived from the database
to a text file...
But it is not working..
My database is like this
--------
text
--------
senthil
i'm just trying to retrive the above string(senthil)...
Wen i run the above program... the following error occurs like this
error C2440: 'initializing' : cannot convert from 'char *' to 'char []'
There are no conversions to array types, although there are conversions to references or pointers to arrays
i'm a beginner to C++ concepts..
What shall i do for this?
can any one plzz help me?
thanks
senthil..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|