Showing posts with label strings in c language using library function. Show all posts
Showing posts with label strings in c language using library function. Show all posts

Saturday, August 6, 2011

Program to Copy a String

//WAP TO COPY A STRING.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char A[20],b[20];
int i,c=0;
clrscr();
puts("\nENTER THE STRING:");
gets(A);
puts("\n\nENTERED STRING IS");
puts("\n\n");
puts(A);
strcpy(b,A);
printf("\n\nAFTER COPYING STRING IS:%s",b);
getch();
}
/*---------------------------------------------------------
OUTPUT
-----------------------------------------------------------


ENTER THE STRING:
ABHISHEK


ENTERED STRING IS



ABHISHEK


AFTER COPYING STRING IS:ABHISHEK
*/

Program t0 Count the number of characters in a string

//WAP TO COUNT THE NO OF CHARACTERS IN A STRING.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int c=0;
clrscr();
puts("\nENTER THE STRING:");
gets(str);
puts("\n\nENTERED STRING IS");
puts("\n\n");
puts(str);
c=strlen(str);
printf("\n\nNUMBER OF CHARACTERS IN A STRING=%d",c);
getch();
}
/*---------------------------------------------------------
OUTPUT
-----------------------------------------------------------

ENTER THE STRING:
ABHISHEK


ENTERED STRING IS



ABHISHEK


NUMBER OF CHARACTERS IN A STRING=8
*/

Programming the Whole World!