Solved

CHAR to upper

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net build a IF/Then Walkthrough Guide 1 233
What is sub-make ? 2 71
draw a Christmas tree by using a nested loop? 26 76
Gaming Software 1 18
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

808 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