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 2 1696
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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
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! :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 { /* .... */ }
|
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 gameloop.cpp
phead.h has all my core declarations in it like my main globals.
main.cpp has all my window initilization functions and my winproc loop.
|
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.
|
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 called gramps (http://www.gramps-project.org) for
MAC OS X.
|
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 "<script>window.location.href='$a'</script>";
Details of the page are passed in the address line and pulled off with
POST. All works fine no problems,
However if the user hits the back button the jump is made again and
| |
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:
http://esnips.com/webfolder/b71bfe95-d363-4dd3-bfad-39999a9e36d0
What i have the biggest problems with now is between line 8 and 23.
How i can move the character trough the game. Other parts of the game
that have with the movement to do is between line 83-114 and...
|
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 Scan(char Search) // this generate the exception
{
// char Search = "Sample text"; //only in this way
|
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 wrong please help ....................i really need serious help
the field picture2, picture4 and video are uploaders
<?php
$firstname = $_POST;
$lastname = $_POST;
$email = $_POST;
$number = $_POST;
$NameOfAdvertisedItem = $_POST;
|
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:
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |