problem:
I give the source of a c program.. is required to indicate how many times is called each function defined in the program and line number
there is a call.
let's say i have lab2.c:
float dist(int *a,int *b,int n){
int i=0;
double d=0;
for (i=1;i<=n;i++){
d+=pow((a-b),2);
}
return sqrt(d);
}
void citire(int *sir,int n){
int i;
for (i=1;i<=n;i++){
printf("dim[%d]=",i);
scanf("%d",&sir);
}
}
int main(){
int n, **m,nr,i,j,a,b;
printf("nr de puncte:");
scanf("%d",&nr);
printf("Dimensiuni:");
scanf("%d",&n);
m=(int **) calloc(nr,sizeof(int*));
for (i=1;i<=nr; i++)
m = (int*) calloc(n,sizeof(int));
for (i=1;i<=nr;i++)
citire(m,n);
float max=0;
for (i=1;i<nr;i++)
for (j=i+1;j<=nr;j++)
if (dist(m,m[j],n)>max){
a=i;
b=j;
max=dist(m,m[j],n);
}
printf("\n distanta maxima este intre punctele %d si %d",a,b);
return 0;
}
the result will be:
dist
4 35 38
3
citire
23 31
2
i have these 2 files:
scen.awk
BEGIN { level=0; }
{
if (index($0,"{")<1) {
if ((level==0) && (index($0,"(")>0) && (index($0,")")>0))
print $0 | cut -d "(" -f1 | cut -d " " -f2;
if (index($0,"{")>0) level++;
if (index($0,"}")>0) level--;
}
}
and sh1.sh
if [ $# -eq 0 ] ;
then echo "nu exista parametrii"
else
for i
do
awk -f scen.awk $i | while read functie
do
echo $functie
grep -n "$functie" $i
nr=`grep -c $functie`
echo $nr
done
done
fi
when i try sh sh1.sh lab2.c it says
print $0 | cut -d "(" -f1 | cut -d " " -f2;
^ parse error
anyone knows how to make this problem work?