This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Showing posts with label strlen(). Show all posts
Showing posts with label strlen(). Show all posts

Tuesday, 6 August 2013

Program to find the length of the string using strlen() function

#include<stdio.h>
void main()
{
char str[50];
int len;
clrscr();
printf("Enter the text: ");
scanf("%s", str);
len=strlen(str);
printf("Length of the string = %d", len);
getch();
}


Tuesday, 2 July 2013

Program to print the String pattern 1

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[100];
int i;
cout<<"Enter the string:";
cin>>str;
for(i=0;i<=strlen(str);i++)
{
cout.write(str,i);
cout<<"\n";
}
getch();
}


Thursday, 27 June 2013

Program to check whether the given string is Palindrome or not (1)

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[50],rstr[50],ch;
int i=0,k=0;
cout<<"Enter the string:";
cin>>str1;
strcpy(rstr,str1);
k=strlen(str1);
for(i=0;i<k/2;i++)
{
ch=rstr[i];
rstr[i]=rstr[k-i-1];
rstr[k-i-1]=ch;
}
if(strcmp(str1,rstr))
cout<<"\n"<<str1<<" is not a palindrome";
else
cout<<"\n"<<str1<<" is a palindrome";
getch();
}