473,947 Members | 26,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert string data type to char type ?

Hi,

I tried to convert string data type to char type so
that I can use strtok.

I have used c_str(). However, still getting error message
when compile .

Any help would be appreciate.

Thanks,

Oct 20 '05 #1
6 5000
tv****@hotmail. com wrote:
Hi,

I tried to convert string data type to char type so
that I can use strtok.

I have used c_str(). However, still getting error message
Which errors?
when compile .


When you compile what?

My crystal ball came just back from repair.
It says that your errors might have to do with the fact that strtok()
modifies the data which is not allowed on what c_str() returns.

Oct 20 '05 #2
<tv****@hotmail .com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I tried to convert string data type to char type so
that I can use strtok.

I have used c_str(). However, still getting error message
when compile .

Any help would be appreciate.


It is very difficult to help without seeing your code. In this case, my
guess is that you are passing what c_str() returns to strtok.

If so, look more closely and realize that what c_str() returns is not
compatible with what strtok takes: 'char const *' vs. 'char *'.

Ali

Oct 20 '05 #3
ptr =strtok(answer. c_str()," \t\n,()");
Error message:
invalid conversion from `const char*' to `char*'

Oct 20 '05 #4
<tv****@hotmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
ptr =strtok(answer. c_str()," \t\n,()");
Error message:
invalid conversion from `const char*' to `char*'


Please quote what you are replying to.

In this case, my guess is that you are showing us some code. Thank you... As
I said in my previous post, look more closely and realize that what c_str()
returns is not compatible with what strtok takes.

In other words, please check the documentations for c_str and strtok. You
may realize that strtok takes a 'char*' and unfortunately, c_str DOES NOT
return that type.

You need to copy the characters that are returned by c_str into a buffer,
then call strtok with that buffer:

#include <string.h>
/* ... */

// WARNING: buffer may be leaked if an exception is thrown
// before getting to the free(buffer) call below
//
// Also, strdup is not standard but exists on many systems

char * buffer = strdup(answer.c _str());
ptr = strtok(buffer, /* ... */);
/* ... */
free(buffer);

Ali

Oct 20 '05 #5
Ali, Thanks a million for your quick help.

Oct 20 '05 #6
In article <11************ **********@g43g 2000cwa.googleg roups.com>,
<tv****@hotmail .com> wrote:
I tried to convert string data type to char type so
that I can use strtok.

I have used c_str(). However, still getting error message
when compile .

Any help would be appreciate.


We don't know exactly what you did since you don't show
a working snippet. In the meantime, this may help:
http://www.comeaucomputing.com/techtalk/#atoi
It may not be what you want, but may have examples enough
to get you through your problem.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
24568
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource = source.GetBuffer(0 ); but i need a char* and so this is not working CString source = _T("TestString");
16
16463
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
15
10860
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
3
57627
by: t2581 | last post by:
Hi , I have database db2 udb 7.2 with following table and datatype CREATE DISTINCT TYPE APP.NOTEPAD AS SYSIBM .CLOB(4096); CREATE TABLE APP.AP_NOTE_PAD ( CONTROL_LOCATION INTEGER NOT NULL , CUSTOMER_NUMBER CHAR(16) NOT NULL , LAST_UP_DATE_TIME TIMESTAMP NOT NULL ,
3
5100
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
5
9077
by: Marc | last post by:
Hello dear, I have a string and every second char is a \0. Can I somehow convert it to a normal string. Or may-be in the underlying code I am doing something wrong, choose the wrong C# type? This is my function I am trying to get right: public static bool GetPrivateProfileSectionAsCS(string appName, string fileName, out string section)
12
13600
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string s = new string((char)107, 1); s += new string((char)62, 1);
14
13588
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h>
0
10814
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
10164
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9985
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9893
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6118
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4540
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.