Well it depends by how you look at it. There might be a lot of things wrong, there might be a few. In my opinion there is a lot.
-<iostream> instead of <iostream.h>
-3 of the library headers are not used or outdated
-namespace std should not be practiced anymore (namespaces in general are bad practice due to conflicts)
-main function missing return definition
-printReverse() has a useless return definition
-getch() belongs to conio.h which is outdated, use std::cin.get() instead
-the for loop inside the main function is producing an incorrect solution
-since your printReverse() function accepts a pointer, it is not wise to predefine its size in the for loop. use strlen from the <string.h> library or (sizeof(array)/sizeof(array[0]) method.
-remember that if a function can be defined before the main function, you will not need a "prototype" for the function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
void printReverse(char* name)
{
for(int i = (sizeof(name) / sizeof(name[0])); i >= 0; i--)
{
std::cout << name[i];
}
}
int main()
{
char name[5] = {'C', 'E', 'S', 'A', 'R'};
std::cout << "\n\n\t\tYour name in reverse: ";
printReverse(name);
std::cout << std::endl;
std::cin.get();
return 0;
}
|