Hi,
There is a C program with
"check_log(log_loc,log_name,path)" in it.
It seems that this C program is calling a check_log function but I didn't see any function called check_log in it.
By the way, the C program itself is called 'check_log'
I am just trying to learn a litter bit about C.
Can someone explain it to me?
Thanks!
Look at the top of the source for #include directives that have "quotes".
Those files probably have a reference to the function - unless you see an extern check_log somewhere in the current file. In that case there is a separate hunk of C code that has the function.
Hi,
Thank you for helping me.
I looked and I didn't see anything in the include has it.
Here is the whole program. What do you think about the check_log line?
========================================
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "stddef.h"
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
//
/ /
/ /
/ /
/ check_log /
/ /
/ /
/ /
/ /
//
check_log(log_loc,log_name,path)
char log_loc[30];
char log_name[30];
char path[80];
{
//
/ Set up variables to be used /
//
char buffer[200];
/*********************************************************/
/* Copy the logs from each machine */
/*********************************************************/
memset\(buffer,0,200\);
sprintf\(buffer,"rcp %s%s %s%s",path,log\_name,log\_loc,log_name\);
system\(buffer\);
/*********************************************************/
/* Check the logs to see if they are readable */
/*********************************************************/
memset\(buffer,0,200\);
strcpy\(buffer,log_loc\);
strcat\(buffer,log_name\);
if\(\(access\(buffer, F_OK\)\) != 0 \) \{
printf\("Error could not find %s.\\n",buffer\);
exit\(0\);
\}
return\(0\);
}
=========================================
"check_log(log_loc,log_name,path)" is the function signature (or interface); it's not calling anything but it is declaring itself and its parameters to the C compiler so that some other module can invoke it. check_log() would be called by some other function external to this body of code.
check_log is part of the check_log.c file.
Is it the standard coding in front of all the C programs for other module to invoke?
Thanks for your help!
I'm not sure I understand your question. I'll see if I can simplify this a bit.
check_log.c is simply a source file that contains a function, check_log(). The "entry point" into the function is this line:
check_log(log_loc,log_name,path)
The check_log function accepts three parameters. check_log's parameter data types are declared as follows:
char log_loc[30];
char log_name[30];
char path[80];
check_log.c could contain additional functions as necessary such as purge_log(), open_log(), etc. It just so happens that it has one function and the source file name "check_log.c" suggests that you can only perform "check log" functionality.
There is no main() function in check_log.c so the function check_log() would be utilized as a utility function by other programs.
A C source file could look like this:
#include "stdio.h"
#include "stdlib.h"
...
function_a(a,b,c)
char a;
int b;
long c;
{
...
}
function_b()
{
...
}
...
main(argc, argv)
int argc;
char *argv[];
{
function_a;
function_b;
....
}
Thanks a lot!
It really helps!