Solved

string functions

Posted on 2006-11-04
3
304 Views
Last Modified: 2010-04-15
i want to write a function void shift(char *) that looks at the first character of its argument and converts the other characters, to be the same case, that is, if the first character is uppercase, it shifts the rest to uppercase; if the first character is lowercase, it shifts the rest to lowercase, and otherwise, it does nothing.
0
Comment
Question by:krampovpi
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17874562
Do you have a question about doing that?
the functions isupper, islower, toupper and tolower may be of interest.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 17875282

void SameCase (char *string)
{
  if (isupper (string)
    // Convert the entire string to upper case
  else if (islower (string))
    // convert the entire string to lower case
}


That's about it.

Kent
0
 
LVL 23

Accepted Solution

by:
Mysidia earned 250 total points
ID: 17875592
That's not right...  string is a pointer to the first character position,
therefore you need to dereference it to access the first character position of the string.

void SameCase (char *string)
{
   if (!isascii(*string)) {
         return;
   }

  if (isupper (*string)
    // Convert the entire string to upper case
  else if (islower (*string))
    // convert the entire string to lower case
}


You can use  toupper/tolower to get the lowercase/uppercase version of any character in the string.

Be sure to check isascii() first;  the islower/isupper/toupper/tolower and many other character functions
require that the argument either be EOF or a valid  unsigned char.

Meaning if the unsigned value of the character is 128 or higher, or the signed value is -1 or less and not EOF,
you need to either not call isupper/islower, OR you need to cast to an unsigned char.

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

770 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