M
MathStudent
Can someone take a look at my code and let me know if you see any
mistakes?
========================
#include <stdio.h>
#include <ctype.h>
#include <conio.h> // Used to make the getch() work
#include <string.h>
int main(void)
{
// Declare variables
// -----------------
char text[70];
char *txtptr;
// Prompt user for line of text
// ----------------------------
printf ("\nEnter a line of text (up to 69 characters):\n");
fgets(text,sizeof text,stdin);
// Ensure that the string terminator is no more than the last
// element in the array.
// -----------------------------------------------------------
txtptr = text;
*(txtptr + strlen(txtptr) - 1) = '\0';
// Converts and outputs the text in uppercase characters.
// ----------------------------------------------------
printf ("\nThe line of text in uppercase is:\n");
txtptr = text;
while (*txtptr != '\0')
putchar( toupper(*txtptr++) );
// Converts and outputs the text in uppercase characters.
// ----------------------------------------------------
printf ("\n\nThe line of text in lowercase is:\n");
txtptr = text;
while ( *txtptr != '\0')
putchar( tolower(*txtptr++));
putchar('\n');
printf("\n");
getch(); // Pauses output
return 0;
} // end main
mistakes?
========================
#include <stdio.h>
#include <ctype.h>
#include <conio.h> // Used to make the getch() work
#include <string.h>
int main(void)
{
// Declare variables
// -----------------
char text[70];
char *txtptr;
// Prompt user for line of text
// ----------------------------
printf ("\nEnter a line of text (up to 69 characters):\n");
fgets(text,sizeof text,stdin);
// Ensure that the string terminator is no more than the last
// element in the array.
// -----------------------------------------------------------
txtptr = text;
*(txtptr + strlen(txtptr) - 1) = '\0';
// Converts and outputs the text in uppercase characters.
// ----------------------------------------------------
printf ("\nThe line of text in uppercase is:\n");
txtptr = text;
while (*txtptr != '\0')
putchar( toupper(*txtptr++) );
// Converts and outputs the text in uppercase characters.
// ----------------------------------------------------
printf ("\n\nThe line of text in lowercase is:\n");
txtptr = text;
while ( *txtptr != '\0')
putchar( tolower(*txtptr++));
putchar('\n');
printf("\n");
getch(); // Pauses output
return 0;
} // end main