Download this source file
/* Strup.c - A function (and demonstration main) to convert a given
* string to all upper case. Notice the use of pointer notation when
* working on a string a character at a time. (A "for" loop could be
* used instead.)
*
* Written 2001 by Wayne Pollock, Tampa Florida USA.
*/
#include
#include
void strup ( char string[] );
int main ( void )
{
char buf[BUFSIZ];
printf( "Please type a line of text: " );
if ( fgets(buf, BUFSIZ, stdin) == NULL ) /* NULL is defined as 0 */
return 1;
/* buf usually has newline at end, unless the input is too long */
printf("\n%-13s %s", "You Typed:", buf);
strup(buf);
printf("%-13s %s", "In uppercase:", buf);
return 0;
}
/* Replaces the input (ASCII) string with an uppercase version of it */
void strup ( char s[] )
{
int i = 0;
while ( s[i] ) /* While not at the end of the string yet (marked by 0). */
{
s[i] = toupper( s[i] );
++i;
}
return;
}
#ifdef COMMENTED_OUT /* Sample output of this program follows: */
Please type a line of text: Hello There on 10/30/98 (Friday)!
You typed: Hello There on 10/30/98 (Friday)!
In uppercase: HELLO THERE ON 10/30/98 (FRIDAY)!
#endif