Solved

string functions

Posted on 2006-11-04
3
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Kent Olsen
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

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

738 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