Can anyone check the code?
Copy all lines below and give a name.c and compile, run with 3 command line arguments.
/*
Add New: create_group_of_usrs.c
Descrip: create a group of user from file
Update : 11th Oct, 2001 */
#include <stdio.h>
#include <time.h>
#define SESSION_ID_FILE "session_id_file"
#define SESSION_ID_FILE_SIZE 1024
int get_session_id(long parent_id, long *session_id)
{
FILE *fp;
time_t t;
struct stat *file_stat;
t=time(NULL);
srand(t);
*session_id=rand();
/* Problem start here*/
stat(SESSION_ID_FILE, file_stat); /*This line is responsible*/
/* How can I compare ?*/
/*
if(file_stat->st_size >= SESSION_ID_FILE_SIZE)
fp = fopen(SESSION_ID_FILE,"w");
else
*/
/* Problem End here*/
fp = fopen(SESSION_ID_FILE,"a");
if(fp==NULL)
{
fp=fopen(SESSION_ID_FILE,"w");
if(fp==NULL) printf("File Open Error\n");;
return 0;
}
fprintf(fp,"%ld %ld %ld\n",*session_id,t,parent_id);
fclose(fp);
return 0;
}
int main (int argc, char *argv[])
{
long parent_id=4678;
long session_id;
printf("<!-- : %s : %s : %s :-->\n",argv[1],argv[2],argv[3]);
/**Statement Okay*/
get_session_id(parent_id, &session_id);
printf("<!-- : %s : %s : %s :-->\n",argv[1],argv[2],argv[3]);
/**Statement: Segmentation error*/
return 0;
}