Read OnLine Cpp Program Example



8 - STRING
PRAC 1 PRAC 2
//wap to print fiend string length
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int l1,l2;
char str1[]="Imacc";
char str2[]="Imacc Education";
clrscr();
l1=strlen(str1);
l2=strlen(str2);

cout<<"\n First String Length="<<l1);
cout<<"\n Second String Length="<<l2);

getch();
}
----------output------
5
15

//strcpy() function in c -->
//copy content of one string to another
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{

char source[]="Imacc";
char target[20];
clrscr();

strcpy(target,source);

cout<<"\n Source String="<<source;
cout<<"\n Target String="<<target;

getch();
}
--------output-------
Source String=Imacc
Target String=Imacc

Previous Next
Download Download