summaryrefslogtreecommitdiff
path: root/659/CH8/EX8.8/exm8_8.sce
blob: 41a558522337d56b8e76f2d3d9f8475828def83e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//                           Example 8.8
//s1,s2 and s3 are three string variables. Write a program to read two string-
//constants in to s1 and s2 and compare whether they are equal or not,join-
//them together. Then copy contents of s1 to variable s3. At the end program-
// should print all three variables and their lengths 


//Read data
printf("Enter two string constants\n");
[s1 s2]=scanf("%s %s");

//Comparing two strings
x=strcmp(s1,s2);
if x~=0 then
    printf("String are not equal\n");
    //Concatinate two strings s1 and s2
    s1=strcat([s1,s2]);
else
     printf("String are equal\n");
end

l1=length(s1);
//Coping s1 to s3
s3=strncpy(s1,l1);
//finding length of strings
l2=length(s2);
l3=length(s3);
//Output
printf("s1 =  %s\t length = %d characters\n",s1,l1);
printf("s2=  %s\t length = %d characters\n",s2,l2);
printf("s3=  %s\t length = %d characters\n",s3,l3);