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<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
void rev(char str[80])
{
char t;
int l = 0, n = strlen(str), k = 0;
for (int i = 0; i <= n; i++)
{
if (str[i] == ' ' || str[i] == '\0')
{
for (int j = i - 1; j > (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 << "Please enter a string : ";
cin.getline(str, 80);
cout << "The original string is : " << str << "\n";
rev(str);
cout << "The new string is : " << str << "\n";
system("pause");
}