ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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....
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....
Could you please post some _extracts_ from your code? I think that would help us to better understand your problem ...
Your question is very confusing. You're talking about atoi() but also about systm_time() working properly and no_of_process() always printing 0.
If atoi() returned the incorrect value (0), you should see 'INCORRECT VALUE' on your screen, so I assume your problem is not with atoi() but with no_of_process(). Correct?
PS And you don't call sysinfo() in no_of_process() ! So the sysinfo structure contains random data (possibly zeroes but not guaranteed without seeing the rest of the code)
Last edited by Wim Sturkenboom; 06-20-2010 at 08:08 AM.
yes i knw its very confusing.... actually i didnt understand y this code is doing like this...
i included sysinfo struct in main also. and u know sometimes my program gives correct ans means correct no of process but when i run this code again it gives 0 no of process...
i have other paramters also in this program like total and free ram, swaped space, etc....
and same 0 i get even for total ram. and swaped space.
sometimes it gives corect ans and sometimes it gives 0....
:-(
I can not look in your code to see what exactly happens, so made a rough copy of yours and modified no_of_process(). I created a global struct sysinfo for the example as I guess that that is how your code works.
It runs properly on my system returning a consistent number of processes each time I run it.
PS: If all options relate to sysinfo, I would call sysinfo before entering the switch.
Please mark your thread as solved using the thread tools just above the opening post.
One little note:
If your original program runs in an endless loop, it will work if you first use option '1' and next option '2'. Option '1' will initialize the sysinfo struct.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.