Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

String Manipulation

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 8 September, 2009

Sample C program to demonstrate various string manipulation functions


#include 
main()
{
    char str[] = "Computer";
    char target[20];
    printf("\n\t String Manipulation");
    printf("\n\t *******************");
    printf("\n\n Strlen");
    printf("\n ******");
    printf("\n The length of the string %s is %d ", str, lenf(str));
    copy(target, str);
    printf("\n\n Strcpy");
    printf("\n ******");
    printf("\n The source strings is %s\n", str);
    printf("\n The target string is %s\n", target);
    printf("\n\n Strcmp");
    printf("\n ******");
    if(compare(str,target)==0)
    printf("\n The strings are %s and %s\n They are equal ", str, target);
    else
    printf("\n The strings are %s and science are equal", str, target);
    if(compare(str, "science") == 0)
    printf("\n The string %s and science are equal\n", str);
    else
    printf("\n The string %s and science are not equal \n", str);
    printf("\n\n Palindrome checking");
    printf("\n *******************");
    if(pal(str, target))
    printf("\n The string %s is a palindrome", str);
    else
    printf("\n The string %s is not a palindrome", str);
    if(pal("window"), target)
    printf("\n The string window is a palindrome");
    else
    printf("\n The string window is not a palindrome");
getch();
}
lenf(char*s)
{
    int l = 0;
    while(*s!='\0')
    {
        l++;
        s++;
    }
    return(l);
}
copy(char*ts, char*ss)
{
    while(*ss != '\0')
    {
        *ts = *ss;
        ss++;
        ts++;
    }
    *ts='\0';
}
compare(char*s1, char*s2)
{
    int i;
    if(lenf(s1)!=lenf(s2))
    {
        i = *s1 - *s2;
        if(i<0)
        return(1);
    }
    else
    return(0);
}
pal(char*s, char*r)
{
    int i,l;
    l = lenf(s);
    for(i=0; i

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy