Find the length of the string without using strlen() function
3
Print a string with one blank space between each char
4
Print a string vertically ( one line break after each char)
5
Print a string in reverse order
Advance on String
No
Detils
1
Copy nth char of string where nth char is a number .
2
Copy a string without using strcpy() .
3
Search a string for presence of a char, if found display the position
4
Search a string inside a string
5
String Print a string vertically ( one line break after each char
6
Print a string in reverse order
7
Delete a string from nth position
8
Search for a char inside a string, if found display the position
9
Remove last char from the string if it is a comma( ,)
10
Take out part of the string starting and ending with two input chars
11
Search for a string inside another string and if found display the position
12
Take out part of the string starting and ending with two input strings
Delete a string from nth Position
#include <stdio.h>
#include <string.h>
int main(void){
int i=12; // position of string to delete
char str[]="welcome to C programming";
str[i]='\0';
printf("%s ", str);
return 0;
}
Listing of all chars of a string vertically with position of each char
#include <stdio.h>
#include <string.h>
int main(void){
int i=12;
char str[]="welcome to C programming";
for(i=0;str[i]!='\0';i++){
printf("\n i= %d => %c ",i,str[i]);
}
return 0;
}
More Practice Questions
Take two strings , one is str1 = ‘welcome ‘ , other one is str2=’ to C ‘. Join the two strings to print out Welcome to C
Hint : Use strcat()
In above code use strncat() and your output should read Welcome to ( without the char C )
Take your first name and last name as inputs , join them by using strcpy() , check the output.
Try the above code without using strcpy()
What is the length of your first name ? Use strlen() to find the length of your full name you got in above code.
Try to reverse your name by using strrev()
Enter your name in Upper case and then use strlwr() to print the string in lower case.
Enter your name in Lower case and then use strupr() to print the string in upper case.
Find the position of first occurrence of char o in this string Welcome to C. Use strchr().
Find the position of last occurrence of char o in this string Welcome to C. Use strrchr().
Ask the user to enter password twice and check if both are same or not , use strcmp()
Ask the user to enter password twice and check if both are same or not , use strcmpi()
Check the difference in using strcmp() and strcmpi()
Search for a string inside another string and return the position of the string if found, use strstr()
Display the masked string ( your name ) by using strset()