Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I was told to use pointers instead of arrays but when I take the [i] off and the

ID: 3640484 • Letter: I

Question

I was told to use pointers instead of arrays but when I take the [i] off and the code went crazy. I just want to know if i need to add something or take away or both.

Write a C program that prompts the user to enter a line of text (up to 50 characters). It should then convert the text entered to uppercase letters and then to lowercase letters, and then to Sentence case.

Your program should use a character array: text[51]. It should use the gets function to prompt the user for the line of text.
Your program must use pointer notation.

The dialog with the user must look like:

Enter a line of text (up to 50 characters):
ThiS is A LiNe of teXt!

The line of text in uppercase is:
THIS IS A LINE OF TEXT!

The line of text in lowercase is:
this is a line of text!

The line of text in sentence case is:
This is a line of text!


Note: The coral text represents the "output" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the blue area above. Again, for clarity only.

Hints:
Your program requires 2 loops (either for or while). One to convert and display the string in uppercase letters, and the other to convert and display the string in lowercase letters.
Your program should use the C standard library functions toupper in one of the loops, and tolower in the other loop, to convert the string. Both of these functions are found in the header file ctype.h.

Real BIG hint:
You can click on the Assign_4_Hint link which provides a solution to the program using array notation. You can use it as a guide, if you so choose. An arrow symbol (->) at the beginning of a particular line of code indicates which lines of code need to be modified.

For an extra challenge, in the sentence case make sure every first letter after a period, exclamation or question mark is uppercase.
Good luck! (Ride of the Valkyries begins to play……)



#include <stdio.h>
#include <ctype.h>



main()
{

/* Declare variables */
/* ----------------- */

char text[51];
char *text_ptr= text;
int i, up;


/* Prompt user for line of text */
/* ---------------------------- */

printf (" Enter a line of text (up to 50 characters): ");
gets(text);

/* Convert and output the text in uppercase characters. */
/* ---------------------------------------------------- */

printf (" The line of text in uppercase is: ");

i = 0;
while ( text_ptr[i] != '') /* could have been: while ( text[i] ) */
putchar( toupper(text[i++]) );

/* Convert and output the text in uppercase characters. */
/* ---------------------------------------------------- */

printf (" The line of text in lowercase is: ");

i = 0;
while ( text_ptr[i] != '') /* could have been: while ( text[i] ) */
putchar( tolower(text[i++]) );

printf (" The line of text in sentence case is: ");

i = 0;
up = 1;
while (text[i] != '') /* could have been: while ( text[i] ) */
{
if(!up)
if (text[i-1]==' ' && toupper(text[i])=='I' && text[i+1]==' ')
up = 1; /* capitalize i if all alone */


if(up)
if (text[i] != ' ')
{
putchar(toupper(text[i++]));
up = 0;
}/* end if */

else

putchar(tolower(text[i++]));

else
{
putchar(tolower(text[i]));
if (text[i] == '?' || text[i] == '.' || text[i] == '!')
up = 1;
i++;
}/* end else*/
} /* end while*/

printf(" ");

return 0;


} /* end main */

Explanation / Answer

please rate - thanks

hope this is good, message me before rating if any problems

#include <stdio.h>
#include <ctype.h>


main()
{

/* Declare variables */
/* ----------------- */

char text[51];
char *text_ptr= text;
int i, up;


/* Prompt user for line of text */
/* ---------------------------- */

printf (" Enter a line of text (up to 50 characters): ");
gets(text);

/* Convert and output the text in uppercase characters. */
/* ---------------------------------------------------- */

printf (" The line of text in uppercase is: ");

i = 0;
while ( *(text_ptr+i) != '') /* could have been: while ( text[i] ) */
     {putchar( toupper(*(text_ptr+i) ));
     i++;
     }

/* Convert and output the text in uppercase characters. */
/* ---------------------------------------------------- */

printf (" The line of text in lowercase is: ");

i = 0;
while ( *(text_ptr+i) != '') /* could have been: while ( text[i] ) */
    {putchar( tolower(*(text_ptr+i)) );
     i++;
     }

printf (" The line of text in sentence case is: ");

i = 0;
up = 1;
while (*(text_ptr+i) != '') /* could have been: while ( text[i] ) */
{
if(!up)
if (*(text_ptr+i-1)==' ' && toupper(*(text_ptr+i))=='I' && *(text_ptr+i+1)==' ')
up = 1; /* capitalize i if all alone */


if(up)
if (*(text_ptr+i) != ' ')
{putchar( toupper(*(text_ptr+i) ));
     i++;
up = 0;
}/* end if */

else

{putchar( tolower(*(text_ptr+i) ));
     i++;
}
else
{
putchar( tolower(*(text_ptr+i)) );
if (*(text_ptr+i) == '?' || *(text_ptr+i) == '.' || *(text_ptr+i) == '!')
up = 1;
i++;
}/* end else*/
} /* end while*/

printf(" ");
return 0;


} /* end main */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote