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;
printf( "\n%-13s %s", "You Typed:", buf ); /* buf has newline at end */
strup( buf );
printf("%-13s %s", "In uppercase:", buf);
return 0;
}
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 /* Samle 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