String reverse

Posted by sameer on Wednesday, June 10, 2009 In : String 
#include<iostream.h>
#include<stdio.h>
void main()
{
char a[50],b[50];
int i,j,count=0;
cout<<"enter the sring:";
gets(a);
for(i=0;a[i]!='\0';++i)
count++;
for(j=count-1,i=0;j>=0,i<count;j--,i++)
{
b[i]=a[j];
}
cout<<b;
}

we first the size of the string then we one by one from the last element store the elements in another string of the same size from the starting


Continue reading...
 

String number of words

Posted by sameer on Wednesday, June 10, 2009 In : String 
#include<iostream.h>
#include<stdio.h>
void main()
{
char a[50];
int i,count=0;
cout<<"enter the string:";
gets(a);
for(i=0;a[i]!='\0';++i)
{
if(a[i]!=' ')
{
if(a[i]!='\0')
{
count++;
}
}
}
cout<<"\nthe number of words in the string  ="<<count;
}

we simply check werther a given word is space or null character if no then we increment the value of count if yes then the loop stops or next increment takes palce.
Continue reading...
 

String size

Posted by sameer on Wednesday, June 10, 2009 In : String 
#include<iostream.h
#include<stdio.h
void main()
{
char a[50];
int i;
cout<<"enter the string:";
gets(a);
for(i=0;a[i]!='\0';++i)
;
cout<<"\nthe size of string is ="<<i;
}

int his program we simply start to check from the starting which number eleement is the nullcharacter which signifies the end of the string and the number so obtained add one to it and that is the size of the string one is added because in array first element has address 0 whreas while counting we take first element as 1...
Continue reading...
 
 

About Me


I AM KUNAL KUMAR SINGH AND IHAVE GREAT PROGRAMMING KNOWLEDGE WHICH I HAVE USED TO DESIGN THIS SITE . KINDY TAKE AS MUCH HELP AND INFO FROM MY SITE AS POSSIBLE .

 

DONATE  ANY AMOUNT FOR C++NOW 

Recent Posts