473,395 Members | 1,404 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,395 software developers and data experts.

Problems whith an header file

Hi everyone,
I've just created a function in a header file that accept a string and
parse but the prototipe of the function return me an exception:

#include <stdio.h>
#include <string.h>

int Scan(char Search[]) // this generate the exception
{
// char Search[] = "Sample text"; //only in this way
that perfectly works!
char *pch;
pch = strtok (Search," -,.");
while (pch != NULL)
{
printf ("%s\n",pch);
//
// some other code here...
//
pch = strtok (NULL, " -,.");
}
}
the function must accept the string.
I use this header whith this sample.cpp
#include "myHeader.h"

int main()
{
Scan("Hi everyone");
return 0;
}
the function return an error when i try to parse a string whith " -,."
Can you help me please?
Thx for all!
Federico

Jul 1 '06 #1
2 1682
On 1 Jul 2006 03:11:34 -0700, "J4CK4L" <fe**************@tiscali.it>
wrote in comp.lang.c++:
Hi everyone,
I've just created a function in a header file that accept a string and
parse but the prototipe of the function return me an exception:
What exception? Always include the compiler, linker, or run time
error message in your post. Don't expect people to read your mind or
guess what the problem is.
#include <stdio.h>
#include <string.h>
Is this C code or C++? In C++, it is much better to use <cstdio> and
<cstring>.
int Scan(char Search[]) // this generate the exception
{
// char Search[] = "Sample text"; //only in this way
that perfectly works!
char *pch;
pch = strtok (Search," -,.");
The strtok() function modified the string, that is it writes a '\0'
over each token as it finds it.
while (pch != NULL)
{
printf ("%s\n",pch);
//
// some other code here...
//
pch = strtok (NULL, " -,.");
}
}
the function must accept the string.
I use this header whith this sample.cpp
#include "myHeader.h"

int main()
{
Scan("Hi everyone");
You are passing a string literal to your function. It is undefined
behavior, in both C and C++, to try to modify a string literal. Try
changing your code like this:

char test [] = "Hi everyone";
Scan(test);
return 0;
}
the function return an error when i try to parse a string whith " -,."
Can you help me please?


The array test is an array of writeable characters that strtok() can
modify.

See also this specific question in the comp.lang.c FAQ:

http://c-faq.com/decl/strlitinit.html

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 1 '06 #2
Thx for all!!
I just made it!
Oh... another question;
how can I see if the word that I scan is match whit another in a file
called wordlist.dat?
thx again! :)

Jul 1 '06 #3

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

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
9
by: Daniel Moree | last post by:
I'm using MS VC++ 6.0 I'm working on a big project. I've currently have several files for this project. Here's the problem. I have one header file phead.h I have two code files main.cpp and...
10
by: puzzlecracker | last post by:
can someone explain why int k; canNOT be definied in .h file? what are general rules for what can/cannot be placed in .h file. FAQ doesn't seem to address this problem.
0
by: Richard Taylor | last post by:
User-Agent: OSXnews 2.07 Xref: number1.nntp.dca.giganews.com comp.lang.python:437315 Hi I am trying to use py2app (http://undefined.org/python/) to package a gnome-python application...
20
by: John | last post by:
I have a page that requests an index number from the user using a form. The submit then calls itself and a php lookup table determines the web page required and then does a jump. echo...
10
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file:...
0
by: J4CK4L | last post by:
Hi everyone, I've just created a function in a header file that accept a string and parse but the prototipe of the function return me an exception: #include <stdio.h> #include <string.h> int...
3
by: Veli | last post by:
Good Day I have published a website and everything works expect for my forms. I can't seem to send the attachments to the email address according to the uploader. I don't know what i am doing...
8
by: Tim Frink | last post by:
Hi, I want to use a callback function together with templates. Let's say I've this code: File a.h: class A { private:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.