Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. /* Fig. 7.10: fig07_10.c
  2. Converting a string to uppercase using a
  3. non-constant pointer to non-constant data */
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. void convertToUppercase( char *sPtr ); /* prototype */
  7. int main( void )
  8. {
  9. char string[] = "characters and $32.98"; /* initialize char array */
  10. printf( "The string before conversion is: %s", string );
  11. convertToUppercase( string );
  12. printf( "\nThe string after conversion is: %s\n", string );
  13.  
  14. return 0; /* indicates successful termination */
  15. } /* end main */
  16. /* convert string to uppercase letters */
  17. void convertToUppercase( char *sPtr )
  18. {
  19. while ( *sPtr != '\0' ) { /* current character is not '\0' */
  20. if ( islower( *sPtr ) ) { /* if character is lowercase, */
  21. *sPtr = toupper( *sPtr ); /* convert to uppercase */
  22. } /* end if */
  23. ++sPtr; /* move sPtr to the next character */
  24. } /* end while */
  25. } /* end function convertToUppercase */
Add Comment
Please, Sign In to add comment