Hi all!
I'm currently having some problems parsing a char array in c++. (And
yes, I'm a half-newbie ;-)) Perhaps you can help me with this:
#include <iostream>
using std::cout;
void outchar(char *outcharstring)
{
cout << outcharstring;
}
void ftest(char *teststring)
{
int i=0;
while (teststring[i] != '\0')
{
outchar(&testst ring[i]);
i++;
}
}
int main()
{
char test[]="Hello.";
ftest(test);
}
Of course, this is just a sample program. But basically I would like
to give a function, that needs the adress of a string, a char, that is
one item of another string.
The output of the code above is:
Hello.ello.llo. lo.o..
What I would like is just "Hello.". How can I accomplish this?
Thanks everybody.
Dennis 12 5114 pl*****@pharmlo g.de (=?ISO-8859-1?Q?Dennis_Pl=F 6ger?=) writes:
Hello, int main() {
char test[]="Hello.";
ftest(test);
}
What I would like is just "Hello.". How can I accomplish this?
What about calling outchar instead of ftest?
Bye,
Chris Dams What I would like is just "Hello.". How can I accomplish this?
void outchar(char *outcharstring) { cout << outcharstring; }
void outchar(char outchar)
{
cout << outchar;
}
so you give only one char to the function. or use your function istead of
ftest
"Chris Dams" <ch****@gamow.s ci.kun.nl> wrote in message
news:bk******** **@gamow.sci.ku n.nl... pl*****@pharmlo g.de (=?ISO-8859-1?Q?Dennis_Pl=F 6ger?=) writes:
Hello,
int main() {
char test[]="Hello.";
ftest(test);
}
What I would like is just "Hello.". How can I accomplish this?
What about calling outchar instead of ftest?
Great idea! Probably the OP wants to output the string character by
character, what do you think?
Chris
Dennis Plöger <pl*****@pharml og.de> spoke thus: I'm currently having some problems parsing a char array in c++. (And yes, I'm a half-newbie ;-)) Perhaps you can help me with this:
I'll try...
void outchar(char *outcharstring) { cout << outcharstring; } void ftest(char *teststring) { int i=0; while (teststring[i] != '\0') { outchar(&testst ring[i]); i++; } }
Of course, this is just a sample program. But basically I would like to give a function, that needs the adress of a string, a char, that is one item of another string.
The output of the code above is: Hello.ello.llo. lo.o..
This is because you're giving the << operator a character pointer...
Hello.\0
^ <- Give this character pointer to cout and you get "Hello."
Hello.\0
^ <- Increment the character pointer - you still have a string, so
"ello." is what gets printed by outchar.
Hello.\0
^ <- Prints "llo." (etc.)
Did that help? cout has the put() member function that allows you to write
one character at a time - presumably what you wanted outchar() to do...
#include <iostream>
using namespace std;
void ftest( char *teststring )
{
int i=0;
char *cp=teststring;
while( *cp ) {
cout.put( *cp++ );
}
cout << endl;
}
int main( void )
{
char *test="Hello.";
ftest( test );
return( EXIT_SUCCESS );
}
--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Christopher Benson-Manica <at***@nospam.c yberspace.org> spoke thus: return( EXIT_SUCCESS );
Um, I don't know which C++ header defines EXIT_SUCCESS - in C it was stdio.h.
If someone could tell me what it is, I'd appreciate it...
--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Christopher Benson-Manica <at***@nospam.c yberspace.org> spoke thus: return( EXIT_SUCCESS );
Um, I don't know which C++ header defines EXIT_SUCCESS - in C it was stlib.h.
If someone could tell me what it is, I'd appreciate it...
--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Dennis Plöger <pl*****@pharml og.de> spoke thus: I'm currently having some problems parsing a char array in c++. (And yes, I'm a half-newbie ;-)) Perhaps you can help me with this:
I'll try...
void outchar(char *outcharstring) { cout << outcharstring; } void ftest(char *teststring) { int i=0; while (teststring[i] != '\0') { outchar(&testst ring[i]); i++; } }
Of course, this is just a sample program. But basically I would like to give a function, that needs the adress of a string, a char, that is one item of another string.
The output of the code above is: Hello.ello.llo. lo.o..
This is because you're giving the << operator a character pointer...
Hello.\0
^ <- Give this character pointer to cout and you get "Hello."
Hello.\0
^ <- Increment the character pointer - you still have a string, so
"ello." is what gets printed by outchar.
Hello.\0
^ <- Prints "llo." (etc.)
Did that help? cout has the put() member function that allows you to write
one character at a time - presumably what you wanted outchar() to do...
#include <iostream>
#include <cstdlib>
using namespace std;
void ftest( char *teststring )
{
int i=0;
char *cp=teststring;
while( *cp ) {
cout.put( *cp++ );
}
cout << endl;
}
int main( void )
{
char *test="Hello.";
ftest( test );
return( EXIT_SUCCESS );
}
--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Christopher Benson-Manica wrote: Christopher Benson-Manica <at***@nospam.c yberspace.org> spoke thus:
return( EXIT_SUCCESS );
Um, I don't know which C++ header defines EXIT_SUCCESS - in C it was stlib.h. If someone could tell me what it is, I'd appreciate it...
It's still in <stdlib.h> (deprecated), and also in <cstdlib>.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Hi all!
Thank you for now.
The problem is, that I take the sample "outchar"-function from a
library (namely the sdlttf-library), which takes the argument as a *
char to generate a surface using a TrueType-font (as a backnote). So I
really need to give the function a single char.
Perhaps some other ideas?
Bye,
Dennis This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of code...
TCHAR myArray;
DoStuff(myArray);
|
by: BlindHorse |
last post by:
Help!!!
I need someone to tell me why I am getting the err msg
error C2440: '=' : cannot convert from 'char *' to 'char'
//====================
#include <iostream>
|
by: Sam |
last post by:
Hello all
I have a two dimensional array (the dimensions are not known) that
needs to be passed
to fortran from c++, allocate the dimensions of the array in fortran
code, do some filling up
of the array in fortran and then accessing it in my c++ code.
Say in my c++ code I have;
extern "C" { void foo_(float **, int &, int &); }
|
by: Pete |
last post by:
Can someone please help, I'm trying to pass an array to a function, do some
operation on that array, then return it for further use. The errors I am
getting for the following code are, differences in levels of indirection, so
I feel it must have something to do with the way I am representing the array
in the call and the return.
Below I have commented the problem parts.
Thanks in advance for any help offered.
Pete
|
by: mwebel |
last post by:
Hi,
i had this problem before (posted here and solved it then) now i have
the same problem but more complicated and general...
basically i want to store the adress of a istream in a char* among
other pieces of information information and retrieve it later... like
this:
***********************
//supossing i have a istream
| |
by: MichK |
last post by:
Hi,
I have a problem with passing a pointer in visual basic.
The thing is I receive an array address of a certain API I call in visual basic. There is no value passed, just an address in the form of a long.
The address is the location of the first element of an array.
Now I need to pass this array to a DLL function.
This function uses the adress to copy the array to a different one.
|
by: S. |
last post by:
Hi all,
Can someone please help me with this?
I have the following struct:
typedef struct {
char *name;
int age;
} Student;
|
by: masso600 |
last post by:
char word;
in = fopen("test.txt", "r");
while(fscanf(in,"%s",&word)!=EOF)
{
/* Print all words */
/* printf("%s\n",&word); */
|
by: arnuld |
last post by:
I am passing an array of struct to a function to print its value. First
I am getting Segfaults and weired values. 2nd, is there any elegant way to
do this ?
/* Learning how to use an array of struct */
#include <stdio.h>
|
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: 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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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...
|
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: 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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |