Solved

string functions

Posted on 2006-11-04
3
302 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

760 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

21 Experts available now in Live!

Get 1:1 Help Now