ex6c.c

Go to the documentation of this file.
00001 #include "../../routines/machine.h"
00002 #include <stdlib.h> 
00003 
00004 /*************************************************************
00005  * Example of a dynamically allocated array of character created here.
00006  * Its size is sent back as an output.
00007  * It is converted into Scilab variable in the interface program.
00008  * The allocated array is freed.
00009  * the Scilab variable is of type stringmat and is not in the argument list of the scilab 
00010  * function. The  Fortran type is Cstringv 
00011  *************************************************************/
00012 
00013 C2F(ccalc6b)(a,m,n,err)
00014      char ***a;
00015      int *m,*n,*err;
00016 {
00017   int i,nstring;
00018   *m=3;
00019   *n=2;
00020   nstring= (*m)*(*n);
00021   *a =(char **) malloc((unsigned) (nstring * sizeof(char *)));
00022   if ( *a ==0) 
00023     {
00024       sciprint("No more space\r\n");
00025       *err=1;
00026       return;
00027     }
00028   for ( i=0  ; i< nstring ; i++) 
00029     {
00030       (*a)[i] = (char *) malloc ((8)*sizeof(char));
00031       sprintf((*a)[i],"char %d",i);
00032       *err=0;
00033     }
00034 }
00035 
00036 
00037 /*************************************************************
00038  * This example shows how a Scilab argument of type stringmat 
00039  * (which is in the calling list of the Scilab function )
00040  * is transmited to a C program. 
00041  * a is a stringmat Scilab argument and a Cstringv Fortran argument 
00042  * a is allocated in the interface 
00043  *************************************************************/
00044 
00045 C2F(ccalc6a)(a,m,n) 
00046      char ***a;
00047      int *m,*n;
00048 {
00049   int i,j;
00050   for ( i = 0 ; i < *m*(*n) ; i++) 
00051     {
00052       char *loc = (*a)[i];
00053       for ( j = 0 ; j < strlen(loc); j++) 
00054         if ( loc[j] =='a' ) loc[j] ='o';
00055     }
00056 }
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 

Generated on Sun Mar 4 15:03:57 2007 for Scilab [trunk] by  doxygen 1.5.1