Solved

CHAR to upper

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now