Output is same as the input where am i making the mistake? Pls check the test version, it prints the ASCII code of 'A' but not A why is it so?
The 1st if condition in the loop is to make sure that the string starts with a valid character only and not space.
void caps(char* p)
{
char* begin=NULL;
char* temp=p;
while(*temp)
{
if((begin == NULL) && (*temp!= ' '))
begin=temp;
if(begin && ((*(temp+1) == ' ' ) || (*(temp+1)=='\0')))
{
toupper(*temp);
begin=NULL;
}
temp++;
}
cout<<p;
}
int main()
{
char str[]={"i like programming"};
cout<< str <<endl;
caps(str);
return 0;
}
Test
If I use printf("%c",toupper(a)) it prints 'A' correctly.
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
char a= 'a';
cout<<toupper(a); //prints ASCII code of A(65) but why not 'A' ?
return 0;
}