Solved

CHAR to upper

Posted on 2004-10-08
3
311 Views
Last Modified: 2010-04-01
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
Comment
Question by:microcoop
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 125 total points
ID: 12264430
try this

#include <ctype.h>

/////

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



hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 12264455
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
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 12264487
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question