String reversal function I have an assignment to create a function that reverses the letters of each word in a string individually. I feel like this should be a rather simple task. I did figure out a solution, although I feel like it uses too many variables as a sort of hack method. Any suggestions on how to make it more efficient/shorter?

#include&lt;iostream&gt;
#include&lt;conio.h&gt;
#include&lt;string.h&gt;

using namespace std;

void rev(char str[80])
{
char t;
int l = 0, n = strlen(str), k = 0;

for (int i = 0; i &lt;= n; i++)
{
    if (str[i] == ' ' || str[i] == '\0')
    {
        for (int j = i - 1; j &gt; (k + i - 1) / 2; l++, j--)
        {
            t = str[j];
            str[j] = str[l];
            str[l] = t;
        }
        k = i + 1;
        l = k;
    }
}

}

void main()
{
    char str[80];
    cout &lt;&lt; "Please enter a string : ";
    cin.getline(str, 80);
    cout &lt;&lt; "The original string is : " &lt;&lt; str &lt;&lt; "\n";
    rev(str);
    cout &lt;&lt; "The new string is : " &lt;&lt; str &lt;&lt; "\n";
    system("pause");
}
main should be int main()
Why C-style strings? Use std::string
One function - one task. You are mixing 2 things into one function:


Reverse chars in a word 
Find words in a sentence separated by spaces




I feel like your problem with too many variables will resolve when you split the tasks you are doing into separate functions.
Use better code formatting (auto-format).
Type mixing - strlen's return value is std::size_t. Do not assign to int. As a follow-up, use a loop index of type std::size_t to match.
This is my preference - not using using namespace std; and system("pause");. I think a lot of posts could be found explaining why.