|
-
Jan 3rd, 2007, 06:17 AM
#1
Thread Starter
Junior Member
How to terminate fetching a string from a database by using a NULL character?
Hai,
i had tried to write a string which is fetched from a database into a file....
Here are my codings to write that fetched string into a text file...
Code:
HANDLE hFile;
DWORD wmWritten;
hFile =CreateFile("D:\\test.text",GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
while (( row = mysql_fetch_row(res_set)) != NULL)
{
char str[100];
char *tmp = str;
strcpy(str, row[2]);
//For writing a file
WriteFile(hFile,str,(DWORD)(sizeof(str)),&wmWritten,NULL);
CloseHandle(hFile);
}
mysql_close(conn);
}
Here row[2] contains a string "senthil"..... when i run the above program
the string "senthil" easily fetched from the database and write into the text
file perfectly... But there are some special garbage characters
like "€'éEY|Ðþ™ž6àþ’@Ðþp@ËÅ å Cí~/ÇÀÿ"
which are also automatically writing into the file....
This is bcoz the "senthil" contains only 7 characters.... but the str array size
is str[100]...
so the remaining space are filled up by these garbage characters and
writing into the file...
so i want to add a null character into string to stop fetching these garbage
characters...
By which method shall i use the null character to stop fetching the garabage
characters....
i'm a beginner to c++...
so any one can help me..
-
Jan 3rd, 2007, 06:35 AM
#2
Frenzied Member
Re: How to terminate fetching a string from a database by using a NULL character?
try
char str[100] = {0};
or better yet
WriteFile(hFile,row[2],(DWORD)(strlen(row[2])),&wmWritten,NULL);
-
Jan 3rd, 2007, 06:49 AM
#3
Thread Starter
Junior Member
Re: How to terminate fetching a string from a database by using a NULL character?
Hi dis,
thanks for ur kind help
Now itz working perfectly....
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
|