Small projects in C using string


Basics on String
NoDetils
1Receive a string and then display the same.
2Find the length of the string without using strlen() function
3Print a string with one blank space between each char
4Print a string vertically ( one line break after each char)
5Print a string in reverse order
Advance on String
NoDetils
1Copy nth char of string where nth char is a number .
2Copy a string without using strcpy() .
3Search a string for presence of a char, if found display the position
4Search a string inside a string
5String Print a string vertically ( one line break after each char
6Print a string in reverse order
7Delete a string from nth position
8Search for a char inside a string, if found display the position
9Remove last char from the string if it is a comma( ,)
10Take out part of the string starting and ending with two input chars
11Search for a string inside another string and if found display the position
12Take 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

  1. 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()
  2. In above code use strncat() and your output should read Welcome to ( without the char C )
  3. Take your first name and last name as inputs , join them by using strcpy() , check the output.
  4. Try the above code without using strcpy()
  5. What is the length of your first name ? Use strlen() to find the length of your full name you got in above code.
  6. Try to reverse your name by using strrev()
  7. Enter your name in Upper case and then use strlwr() to print the string in lower case.
  8. Enter your name in Lower case and then use strupr() to print the string in upper case.
  9. Find the position of first occurrence of char o in this string Welcome to C. Use strchr().
  10. Find the position of last occurrence of char o in this string Welcome to C. Use strrchr().
  11. Ask the user to enter password twice and check if both are same or not , use strcmp()
  12. Ask the user to enter password twice and check if both are same or not , use strcmpi()
  13. Check the difference in using strcmp() and strcmpi()
  14. Search for a string inside another string and return the position of the string if found, use strstr()
  15. Display the masked string ( your name ) by using strset()

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer