summaryrefslogtreecommitdiff
path: root/37/CH1/EX1.3/Solved3.sci
blob: 99b393813d53c3adfeb16fc4c5836fce41810cc9 (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
//Solved Example 5:
//Writing a name from the given structure and 
//counting the number of alphabets printed
function[l]=strlen(str)
  i=1;
  l=0;
  [j,k]=size(str)
  for  i=1:k
    l=l+length(str(i));
  end
endfunction
function[count]=writename(name)
  printf("\n");
  printf("%s",name.first);
  printf("%c",'  ');
  printf("%s",name.midinit);
  printf("\t");
  printf("%s",name.last);
  printf("\n");
  
  a=string(name.first);
  count=strlen(a);
  a=string(name.midinit);
  count=count+strlen(a);
  a=string(name.last);
  count=count+strlen(a);
  disp(count,"Count is:");
endfunction
//Calling Routine
name=struct('first','praveen','midinit','rajeev','last','chauhan');
count=writename(name)