Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Tuesday, 2 April 2013

Convert the string into lowercase


Convert the string into lowercase:-

Q)Write a program to enter string and convert string(Character Array) into lowercase.

Note:-You can also create this program in c++(c plus plus),java,perl,c#(c sharp) languages etc. with the same logic.

P:void main()
{
char string[40];
int i;
printf("Enter String");
gets(string);
for(i=0;string[i]!='\o';i++)
{
if(string[i]>65 && string[i]<=90)
string[i]=string[i]+32;
}
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Convert a string into uppercase


Convert string into uppercase:-

Q)Write a program to enter string(character array) and convert string into uppercase.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic.

P:void main()
{
char string[40];
int i;
printf("Enter String");
gets(string);
for(i=0;string[i]!='\o';i++)
{
if(string[i]>97 && string[i]<=122)
string[i]=string[i]-32;
}
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Sunday, 31 March 2013

Copy String into the another String


Copy String into the another String:-

Function used-strcpy.This function is used to copy string(Character Array) into another string.

Q)Write a program to enter string and copy string into another string.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string1[40],string2[40];
printf("Enter String");
gets(string1);
strcpy(string2,string1);
puts(string2);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Count the length of String with the help of program


Count length of String:-

Function used-strlen.This function is used to count the length of string.

Q)Write a program to enter string(character array) and count the length of string(without function).


Note:-You can also create this program in c++(c plus plus),java,perl,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string[40];
int i,l;
clrscr();
printf("Enter String");
gets(string);
l=0;
for(i=0;string[i]!='\o';i++)
{
l=l+1;
}
printf("Length of string");
getch();
}
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Tuesday, 26 March 2013

Reverse of String


Reverse of String:-


Q)Write a program to enter string(Character Array) and print the reverse of string.

Function used-strrev.This function is used to reverse a string.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string[40],reverse[40];
printf("Enter String");
gets(string);
strrev(string);
strcpy(reverse,string);
puts(reverse);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Compare two Strings(Character Array)


Compare two Strings(Character Array):-

Function used-strcmp.This function is used to compare two string.

Q)Write a program to enter two string and compare two strings.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string1[40],string2[40];
printf("Enter first String");
gets(string1);
printf("Enter second String");
gets(string2);
if(strcmp(string1,string2)==0)
printf("String is equal");
else
printf("String is not equal");
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Concatenate of String or Character Array


Concatenate of Strings:-

Function used-strcat.strcat function is used to connect two string together.

Q)Write a program to enter two string and join the strings.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string1[40],string2[40];
printf("Enter first String");
gets(string1);
printf("Enter second String");
gets(string2);
strcat(string1,string2);
puts(string1);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Character Array Or a String


Character Array Or a String is the sequence of characters which are used to create meaningful programs.String is terminated by null character(\o).

input=gets()

output=puts()

String(Formatting)=%s

Declaration and Initialisation of String:-

Syntax:-

data type string name[size];

Example:-

char string[40];

Some important operation performed in a string:-

1)Read and Write string

2)Add string

3)Copy string

4)Concatenate string

5)Compare string etc.

Simple/Basic program of Character Array Or a String:-

Q)Write a program to enter string and display the string.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string[40];
printf("Enter String");
gets(string);
printf("String are as follows");
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.