Solved

CHAR to upper

Posted on 2004-10-08
3
313 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 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