microcoop
asked on
CHAR to upper
I have tried to use strupr(char) and it worked on vs.net's c++, but once I compiled on Linux it didn't work. Is there another function to change a char[4] to all uppercase?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This would work anywhere
#include <iostream>
using namespace std;
int main( int argc, char *argv[] ) {
char s[5] = "abcd" ;
for ( int i = 0; i < 4 ; i ++ ) {
s[i] = s[i] - 32 ;
}
cout << s ;
system ( "PAUSE" ) ;
return 0 ;
}
Amit
#include <iostream>
using namespace std;
int main( int argc, char *argv[] ) {
char s[5] = "abcd" ;
for ( int i = 0; i < 4 ; i ++ ) {
s[i] = s[i] - 32 ;
}
cout << s ;
system ( "PAUSE" ) ;
return 0 ;
}
Amit
#include <stdio.h>
#include <ctype.h>
int main()
{
char mychar[4]={'a', 'b', 'c', 'd'};
int i;
for ( i=0; i<3; i++ )
printf("%c ", mychar[i]);
printf("\n");
for ( i=0; i<3; i++ )
mychar[i] = toupper(mychar[i]);
for ( i=0; i<3; i++ )
printf("%c ", mychar[i]);
printf("\n");
}
hongjun