Change string case using its pointer : String Case « String « C / ANSI-C






Change string case using its pointer

Change string case using its pointer
  
#include <ctype.h>
#include <stdio.h>

int main(void)
{
  char str[80], *p;

  printf("Enter a string: ");
  gets(str);
  p = str;

  while( *p ) {
    *p = toupper(*p);
    p++;
  }

  printf("%s\n", str); /* uppercase string */

  p = str; /* reset p */

  while( *p ) {
    *p = tolower(*p);
    p++;
  }

  printf("%s\n", str); /* lowercase string */

  return 0;
}


           
       








Related examples in the same category

1.Convert string to upper case and lower case