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

Can you tell me what is wrong with this code . #include <stdio.h> #include <ctyp

ID: 3931325 • Letter: C

Question

Can you tell me what is wrong with this code .

#include <stdio.h>

#include <ctype.h>

int main()

{

       char line[100];

       printf("Enter a line of text: ");//Prompts for a string.

       scanf_s("%[^ ]s", line);//Reads a string, terminated by a new line.

       printf("Original String: %s ", line);//Prints the original string.

       int i = 0;

       printf("Upper case String: ");

       while (line[i] != '')//For each character in the original string.

              printf("%c", toupper(line[i++]));//Prints its upper case equivalent character.

       printf(" ");//Move on to the next line.

       i = 0;

       printf("Lower case String: ");

       while (line[i] != '')//For each character in the original string.

              printf("%c", tolower(line[i++]));//Prints its lower case equivalent character.

       printf(" ");//Move on to the next line.

}

Explanation / Answer

Answer

error is at line scanf_s("%[^ ]s", line);//Reads a string, terminated by a new line.

made it as

scanf("%[^ ]s", line);

Solution.c

#include <stdio.h>//header file for input output function

#include <ctype.h>//Header file "ctype.h" includes numerous standard library functions to handle characters

int main()

{// main function

       char line[100];

       printf("Enter a line of text: ");//Prompts for a string.

       scanf("%[^ ]s", line);//Reads a string, terminated by a new line.

       printf("Original String: %s ", line);//Prints the original string.

       int i = 0;

       printf("Upper case String: ");

       while (line[i] != '')//For each character in the original string.

              printf("%c", toupper(line[i++]));//Prints its upper case equivalent character.

       printf(" ");//Move on to the next line.

       i = 0;

       printf("Lower case String: ");

       while (line[i] != '')//For each character in the original string.

              printf("%c", tolower(line[i++]));//Prints its lower case equivalent character.

       printf(" ");//Move on to the next line.

}

output

Enter a line of text: Jhon Bush                                                                                                                                          

Original String: Jhon Bush                                                                                                                                               

Upper case String: JHON BUSH                                                                                                                                             

Lower case String: jhon bush  

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