Ugh.
I am taking a c++ foundations course, and all was well until the moment came where I had to break my prototypes out into .h files. Until this point, all my prototyping has been done with ints, doubles, etc. - char seems to be different and vexing.
test.h
void display(char* str)
---------------------------------------------
int main()
{
#include "test.h"
char str[] = "hello";
display();
}
At this point I get an error on compile and nothing I have done, or none of the reference material I have at my disposal is fixing the prolem.
HELP!
9 2560
Ugh.
I am taking a c++ foundations course, and all was well until the moment came where I had to break my prototypes out into .h files. Until this point, all my prototyping has been done with ints, doubles, etc. - char seems to be different and vexing.
test.h
void display(char* str)
---------------------------------------------
int main()
{
#include "test.h"
char str[] = "hello";
display();
}
At this point I get an error on compile and nothing I have done, or none of the reference material I have at my disposal is fixing the prolem.
HELP!
Your include commands should be at the top of the file and don't forget to add a semicolon after your prototype. Also, your display function takes a char pointer but you aren't passing it any. Make sure that you actually have the body for the display function. -
#include "test.h"
-
-
int main()
-
{
-
char str[] = "Hello";
-
display(str);
-
return 0;
-
}
-
Don't get confused by characters, they are just another data type like ints or doubles.
Thanks! - that was the vital piece -
I am now getting a return value of ''__Z5helloPc' - which is not right.
The whole program looks like: -
#include <iostream>
-
using namespace std;
-
#include <limits>
-
int main()
-
{
-
#include "testing.h"
-
char str[] = "hello";
-
hello(str );
-
-
-
cout << str[0]
-
<< str[1]
-
<< str[2]
-
<< str[3]
-
<< str[4]
-
<< endl;
-
-
-
cout << str[4]
-
<< str[3]
-
<< str[2]
-
<< str[1]
-
<< str[0]
-
<< endl;
-
-
return 0;
-
}
-
I am not sure where the garbage is coming from.
it should return "hello
olleh"
Which it does when the function is in main().
Thanks! - that was the vital piece -
I am now getting a return value of ''__Z5helloPc' - which is not right.
The whole program looks like: -
#include <iostream>
-
using namespace std;
-
#include <limits>
-
int main()
-
{
-
#include "testing.h"
-
char str[] = "hello";
-
hello(str );
-
-
-
cout << str[0]
-
<< str[1]
-
<< str[2]
-
<< str[3]
-
<< str[4]
-
<< endl;
-
-
-
cout << str[4]
-
<< str[3]
-
<< str[2]
-
<< str[1]
-
<< str[0]
-
<< endl;
-
-
return 0;
-
}
-
I am not sure where the garbage is coming from.
it should return "hello
olleh"
Which it does when the function is in main().
It's probably coming from function.
And what do u mean by:
"Which it does when the function is in main()."?
Ur hello function is currently in main.
Please can u give us more info..
Savage
It's probably coming from function.
And what do u mean by:
"Which it does when the function is in main()."?
Ur hello function is currently in main.
Please can u give us more info..
Savage
my testing.h header file contains:
if I put -
char * str = new char[5];
-
str = "hello";
-
in the main body of my program, it returns my expected results. It is when I include the header file, I get the garbage return value.
my testing.h header file contains:
if I put -
char * str = new char[5];
-
str = "hello";
-
in the main body of my program, it returns my expected results. It is when I include the header file, I get the garbage return value.
Can we see function hello definition?
Savage
Can we see function hello definition?
Savage
Savage,
This is where I am getting ignorant. Function hello only exists as a prototype in the header file. everything else I have posted is the entirety of the program.
I am a rank beginner at OOP, so please forgive me if I am missing something or mis-understanding something.
The goal of the program is to use pointer arithmatic to display the string "hello" forwards and bachwards . As far as coding it without using the header file, I am successful.
So far, I have been unable to include the header in any meaningful way. Hence my frustration.
Savage,
This is where I am getting ignorant. Function hello only exists as a prototype in the header file. everything else I have posted is the entirety of the program.
I am a rank beginner at OOP, so please forgive me if I am missing something or mis-understanding something.
The goal of the program is to use pointer arithmatic to display the string "hello" forwards and bachwards . As far as coding it without using the header file, I am successful.
So far, I have been unable to include the header in any meaningful way. Hence my frustration.
I allready know all that and this is probably ur problem: - int main()
-
{
-
#include "testing.h"
-
char str[] = "hello";
-
hello(str );
As ilikepython said ur include commands should be at the top of the code.
(Sorry,didn't noticed it when I was looking before few minutes)
Savage
-
int main()
-
{
-
#include "testing.h"
-
char str[] = "hello";
-
hello(str );
-
The problem, it appeared was on the final line above, with referenced the prototype, but didn't have any play with the variables. Removing that line fixed the output.
Thanks!
-
int main()
-
{
-
#include "testing.h"
-
char str[] = "hello";
-
hello(str );
-
The problem, it appeared was on the final line above, with referenced the prototype, but didn't have any play with the variables. Removing that line fixed the output.
Thanks!
Allways a pleasure..
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave |
last post by:
Hi
I m facing strange problem...
I have one field char type data length 1..
It has data either 1 or 2 in all the field tht I have
checked through enterprise manager.
I'm running query
"select...
|
by: Keith Dick |
last post by:
I'm trying to use the free C/C++ compiler for .NET. When I debug a
program with CORDBG and use the p command to display a char array, it
displays the data as numbers, not as characters. How can I...
|
by: Steffen Fiksdal |
last post by:
I have a function that base64 decodes some data. The incoming data is
received as "const char*" (BASE64 characters are always safe ASCII
characters, meaning they will always fit in a signed char...
|
by: Martin Moser |
last post by:
Does somebody knows, if theres a way to display any file (tiff, doc, pdf,
.....) "inline" on an asp.net site? What I want to do is, to display a file,
which is stored in the DB, and some...
|
by: Geoff Pennington |
last post by:
My VB.Net app reads an Excel file, processes it one row at a time, and when
processing is complete writes the row to a database. The typical file will
have several thousand rows and may take a...
|
by: Tim |
last post by:
Can anyone tell me how can i use ASP to display a file in the web browser?
the file is located on the server in C:\temp directory. It can be any file.
Is there any way that i can do this?
Thank...
|
by: shapper |
last post by:
Hello,
I am trying to convert an Asp.Net XML sitemap file in a Google XMl
sitemap file using a XSL file using an HttpHandler.
Everything seems well in my code but I am getting an error:
XML...
|
by: Matt |
last post by:
Is there a way to display the file selection window for a file input
field via JavaScript? My goal is to emulate the behavior seen in
Yahoo! Mail BETA. When adding an attachment, it displays a...
|
by: BASSPU03 |
last post by:
I used the Common Dialog API to store file paths on my form's underlying table. These paths are displayed in a textbox that I can click to open the selected file.
Having stored the file paths in...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
| |