//My function is but the problem is that i dont have a proper working main function
void reverse(int a[], int n) { // function: Reverses the elements of a. // parameters: // a inout array of values. // n in number of values in a, a[0]..a[n-1] // returns: nothing for (int i=0; i<n/2; i++) { int temp = a; a = a[n-i-1]; a[n-i-1] = temp; } return;

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.

Edited 6 Years Ago by Nick Evan: n/a

/*My function is but the problem is that i dont have a proper working main function*/

void reverse(int a[], int n) 
{ 
 
 for (int i=0; i<n/2; i++) { 
 
int temp = a[i];
 
 a[i] = a[n-i-1];
 
 a[n-i-1] = temp; 
 
} 
 
}

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.

Edited 6 Years Ago by Nick Evan: n/a

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;
}

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.

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.

Edited 6 Years Ago by Nick Evan: n/a

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

This question has already been answered. Start a new discussion instead.