FY_BCA_C_SLIP 7_2



Slip no : 7_2 wite c prog to perform following opeartions on string using user defined function 1.calculate length of string
2.copy one string to another


#include<stdio.h>
#include<conio.h>

int length(char str[])
{
int len=0,i; for(i=0;str[i]!='\0';i++) len++;
return len;
}

void cpy(char str[])
{
int k=0,i; char s[20];

for(i=0;str[i]!='\0';i++)
{
s[k]=str[i];
k++;
}
s[k]='\0';

printf("\n copied string is : %s ",s);
}

main()
{
char s1[20]; int ans; clrscr();
printf("\n Enter string be calculate length "); scanf("%s",s1);
//                  gets(s1);
ans=length(s1);
printf("\n Length of given string is %d ",ans); printf("\n Enter string to be copy ");
scanf("%s",s1);//gets(s1);
cpy(s1);
getch();

}

No comments:

Post a Comment