hii
i m using atoi() to convert char value to int. and then passing that int as a swtich variable.
switch goes in a case and exectuing that particualr function but returning 0 value....
for example: i am finding no of process() and system up time().
when switch program goes in system up time it gives right values means correct no of days, hrs , min and sec but when it goes in no of process() it gives 0 answer....
why is it so???? plz help!!
heres the code..
int snmpget()
{
char recv_data[1024];
// code to recieve msgs from client
bytes_read = recvfrom(sock,recv_data,1024,0,
(struct sockaddr *)&client_addr, &addr_len);
recv_data[bytes_read] = '\0';
printf("\n(%s , %d) requested : \n",inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
printf("%s", &recv_data);
fflush(stdout);
int i=atoi(recv_data); // converting recv_data into integer
switch(i)
{
case 1:
systm_time();
break;
case 2:
no_of_process();
break;
default:
printf("\tINCORRECT VALUE");
break;
}
}
// this function is printing right values for hrs, min, sec, and days
int systm_time()
{
char send_data[1024];
if(sysinfo(&sys_info) != 0)
perror("sysinfo");
// Uptime
days = sys_info.uptime / 86400;
hours = (sys_info.uptime / 3600) - (days * 24);
mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
printf("Uptime: %ddays, %dhours, %dminutes, %ldseconds\n",
days, hours, mins, sys_info.uptime % 60);
}
// this functions is returning 0
int no_of_process()
{
// Number of processes currently running.
printf("Number of processes: %d\n", sys_info.procs);
}