summaryrefslogtreecommitdiff
path: root/659/CH8/EX8.8/exm8_8.sce
diff options
context:
space:
mode:
Diffstat (limited to '659/CH8/EX8.8/exm8_8.sce')
-rwxr-xr-x659/CH8/EX8.8/exm8_8.sce32
1 files changed, 32 insertions, 0 deletions
diff --git a/659/CH8/EX8.8/exm8_8.sce b/659/CH8/EX8.8/exm8_8.sce
new file mode 100755
index 000000000..41a558522
--- /dev/null
+++ b/659/CH8/EX8.8/exm8_8.sce
@@ -0,0 +1,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);
+