Linux.com

calling system with linux and C

Link to this post 26 Aug 11

Okay i'm learning C and enjoying it pretty well, but I'm running into problems cross platform due to some slight differences. In windows I can use in a console application for example system("pause"); to pause the program until enter is pressed, etc... but that doesn't apply to Linux and the terminal window.


Is there is a list of ways to call system and what they do with C and Linux? Could use a list for Linux and Windows actually since we're on the topic. Let me know i've looked for one haven't had any luck so far though.

Link to this post 26 Aug 11

RSims wrote:

Okay i'm learning C and enjoying it pretty well, but I'm running into problems cross platform due to some slight differences. In windows I can use in a console application for example system("pause"); to pause the program until enter is pressed, etc... but that doesn't apply to Linux and the terminal window.


Is there is a list of ways to call system and what they do with C and Linux? Could use a list for Linux and Windows actually since we're on the topic. Let me know i've looked for one haven't had any luck so far though.

You are doing it wrong (NOTE: I'm no expert)

If you are doing system calls from your program you'll get to problems because the system calls are different in every platform ( there are some standards, like POSIX which define the basic syscalls that must be present in every system...)

You'll have to know what OS standard you want to follow and then use only those system calls. That or to check which OS your app is running and then call one syscall or another depending on the platform

Regards

Link to this post 27 Aug 11

I figured that much out when I was trying to use system("cls"); to clear previous terminal garbage. I'm sure system calls are listed somewhere for linux and windows 7. Let me know if anyone finds them because I have had no luck looking for them.

Link to this post 27 Aug 11

As Marc Deop says this is the wrong way of doing things, especially if your learning C as those stuff is no part of C.

Just use getchar() instead.

http://www.gidnetwork.com/b-61.html
http://www.gidforums.com/t-12871.html

Link to this post 27 Aug 11

RSims wrote:

I figured that much out when I was trying to use system("cls"); to clear previous terminal garbage. I'm sure system calls are listed somewhere for linux and windows 7. Let me know if anyone finds them because I have had no luck looking for them.

10secs search on google:

http://www.gnu.org/software/guile/manual/html_node/POSIX.html

Regards

Link to this post 27 Aug 11

um, I'm not sure if that is what I was looking for or not... but I guess I need to do more research either way... Thanks for the help.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board