Sorry, but you can't really expect that someone will understand your question or function if you post like this.
Retry and please use CODE-tags, indent your code, post the complete code and ask a clear question.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
the problem is that i dont have a proper working main function
I see...but there are more problems. I'm guessing that you want to reverse a string?? Have a look at this , last post. It's in dutch but I think you will find the code helpfull.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Here's a working example of how to reverse a string using a function. Hope this helps, good luck!
#include <iostream>
using namespace std;
void ReverseString(char string1[], char reversed[]);
int main()
{
const int MAX = 80;
char string1[MAX];
char reversed[MAX];
cout << "Enter your string: ";
cin.get(string1,MAX);
ReverseString(string1, reversed);
return 0;
}
void ReverseString(char string1[], char reversed[])
{
int length = strlen(string1);
for (int i=length-1, j=0; i>=0; i--, j++)
reversed[j] = string1[i];
for (i=0; i<length; i++)
cout << reversed[i];
cout << endl;
}
may4life
Junior Poster in Training
57 posts since Oct 2006
Reputation Points: 13
Solved Threads: 2
Here's a working example of how to reverse a string using a function. Hope this helps, good luck!
#include <iostream>
using namespace std;
void ReverseString(char string1[], char reversed[]);
int main()
{
const int MAX = 80;
char string1[MAX];
char reversed[MAX];
cout << "Enter your string: ";
cin.get(string1,MAX);
ReverseString(string1, reversed);
return 0;
}
void ReverseString(char string1[], char reversed[])
{
int length = strlen(string1);
for (int i=length-1, j=0; i>=0; i--, j++)
reversed[j] = string1[i];
for (i=0; i<length; i++)
cout << reversed[i];
cout << endl;
}
You really should compile and test your code before posting. It contains several bugs that may just confuse the OP.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
void ReverseString(char string1[], char reversed[])
{
int i, length = strlen(string1);
for (int i=length-1, j=0; i>=0; i--, j++)
reversed[j] = string1[i];
for (i=0; i<length; i++)
cout << reversed[i];
cout << endl;
cin.get();
cin.get();
}
Here's the reviewed code from may4life.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Hmm, dont know whats going wrong.. I copied and pasted my code from here and still works no prob on my compiler :-S
I always test my code and post it with 0 errors and 0 warnings.. Maybe there might be a mix up with our compilers.. Sorry for anyone who had problems with my code..but they work for me :-S
may4life
Junior Poster in Training
57 posts since Oct 2006
Reputation Points: 13
Solved Threads: 2