Originally Posted by
vart
to show that swap function is called only from the qsort probably
Yeah, I think you're right. Here is what happens when I put the prototype printagain() inside the function definition printme1().
Code:
[cdalten@localhost oakland]$ more prot.c
#include <stdio.h>
void printme1(void)
{
char arr[] = "test";
void printagain(char *);
printf("This is inside printme1()\n");
printagain(arr);
}
void printme2(void)
{
char arr[] = "test";
printf("This is inside printme2()\n");
printagain(arr);
}
void printagain(char *s) {
printf("%s\n", s);
}
int main(void)
{
printme1();
printme2();
return 0;
}
[cdalten@localhost oakland]$ gcc -g -Wall prot.c -o prot
prot.c: In function ‘printme2’:
prot.c:18: warning: implicit declaration of function ‘printagain’
prot.c:6: warning: previous declaration of ‘printagain’ was here
prot.c:18: error: incompatible implicit declaration of function ‘printagain’
prot.c:6: error: previous implicit declaration of ‘printagain’ was here
[cdalten@localhost oakland]$
And now here is what happens when I put the prototype for printagain() at the very top. Ie, not in the function definitions.
Code:
[cdalten@localhost oakland]$ more prot.c
#include <stdio.h>
void printagain(char *); /*this is no longer inside the function defintion*/
void printme1(void)
{
char arr[] = "test";
printf("This is inside printme1()\n");
printagain(arr);
}
void printme2(void)
{
char arr[] = "test";
printf("This is inside printme2()\n");
printagain(arr);
}
void printagain(char *s) {
printf("%s\n", s);
}
int main(void)
{
printme1();
printme2();
return 0;
}
[cdalten@localhost oakland]$ gcc -g -Wall prot.c -o prot
[cdalten@localhost oakland]$ ./prot
This is inside printme1()
test
This is inside printme2()
test
[cdalten@localhost oakland]$