[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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?
0
microcoop
Asked:
microcoop
  • 2
1 Solution
 
hongjunCommented:
try this

#include <ctype.h>

/////

for ( i=0; i<3; i++ )
    mychar[i] = toupper(mychar[i]);



hongjun
0
 
hongjunCommented:
complete program here


#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
0
 
Sys_ProgCommented:
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
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now