473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with string declaration!

10
Hi everyone

I want to pass a temp_string from a function to another function so I declared it as char*
but when I did this:

char* tmp_string;
assert(tmp_string=malloc(((MAXCHARS)*sizeof(char)) )!=NULL);
tmp_string=strtok(string,"|");
return tmp_string;

I got segmentation fault,How can I declare it?
May 15 '07 #1
2 1242
toktam
10
Hi everyone

I want to pass a temp_string from a function to another function so I declared it as char*
but when I did this:

char* tmp_string;
assert(tmp_string=malloc(((MAXCHARS)*sizeof(char)) )!=NULL);
tmp_string=strtok(string,"|");
return tmp_string;

I got segmentation fault,How can I declare it?
Another question ;)
when we declare a string as char*,how can we copy a string to it?
May 15 '07 #2
gpraghuram
1,275 Expert 1GB
HI,
Check whether the variable string (tmp_string=strtok(string,"|");) has a proper memory to it or it is not NULL.
You can copy a value to char* using strcpy function.
First get a hold of the string functions, then u can figure out the mistake u are doing.(Use this link)

Thanks
Raghuram
May 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Piotre Ugrumov | last post by:
Excuse me for the previous post, I have tried to modify the classes of the Savannah example and now I succeed to compile the classes but I have a strange problem. When I declar an object of the...
13
by: Winbatch | last post by:
Hi, If this should be directed to another group, please let me know... I've been working with templates for a few weeks and have been able to develop some nice code on solaris using the Forte C++...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
14
by: bob | last post by:
Can anyone help me connect to SQL Server??? I am new to all this... it is been a titanic struggle consuming hours & days & .... I am trying to create an SQL database programatically. But my...
4
by: shreshth.luthra | last post by:
Hi All, I am having a GUI which accepts a Unicode string and searches a given set of xml files for that string. Now, i have 2 XML files both of them saved in UTF-8 format, having characters...
12
by: =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= | last post by:
Hi, I need to initialize my class level dictionary (in .Net 2.0). I wanted to make it inline and employ anonymous methods as I do not use this code for anything else. Something similar to the...
6
by: Scoots | last post by:
I know the usually applied workaround for multiple definitions of header files, but I have a problem on this one. This time, I can't just ifndef the header file that defines my structure. So...
4
by: Chris Forone | last post by:
hello group, why have i to bracket the second ctor param in the following example? thx & hand, chris #include <fstream> #include <iterator> int main()
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.