In the following exercises, you need to get strings from the user. Use the following code to get a string, and remove the newline character.

...
#include <string.h>
...
char string[100];
fgets(string, sizeof(string), stdin);
// use the following to get rid of the newline character
// that gets attached to the end of the input string
string[strcspn(string, "\n")] = '\0';
...

Question 01

Write a C program to concatenate two strings entered by the user without using strcat().

Question 02

Write a C program that calculates the length of a string entered by the user without using the strlen function.

Question 03

Write a C program that converts a string entered by the user to uppercase. Use the function toupper() from header file ctype.h to convert a character to uppercase.

...
#include <ctype.h>
...
// The value of ch after running the following statement is 'A'
char ch = toupper('a');
...

Question 04

Write a C program that finds the first occurrence of a character in a string entered by the user.

Question 05

Write a C program that counts the number of times a character appears in a string entered by the user.

Last modified: Saturday, 23 November 2024, 6:25 PM