开发者

Practical examples for C practice?

I know several programming languages including Objective-C, Java, C#, and python, and C. However, I need to brush up my efficiency in C.

In most languages that happen to be high-level, object-based, and GUI-oriented, I create a few standard object-oriented examples to orient me to the language/framework. I usually create a "car" example where I model a car and allow the user to adjust the speed, watching the mileage increase.

However, something tells me this example is not as practical to carry over to C in a unix command-line setting. What are some good basic ideas to 'test myself' in a unix command-line based C setting?

Thanks for any input!

EDIT: Thanks for the answers. My basic concern with the car example is that I shouldn't be attemp开发者_开发技巧ting object-oriented in this environment, but rather do something that is more suited to the language. Thanks to Duck for the suggestion of recreating command line utilities.


Get yourself a copy of

C Programming Language (2nd Edition)


Recreate (for the umpteenth time) any of the standard command line utilities - cat, ls, touch, more, less, etc. Write a basic shell. These will exercise C and re-familiarize you with unix system calls.


try this: http://www.gowrikumar.com/c/

They provide puzzles and problems, have you spot them, and then you can check your answer. Might not be enough for what you asked for, but it might be a start?


You can write something similar with structures. Create a car structure and create functions that operate on the Car structure passed as a pointer (explicit this parameter). You can use conio.h or ncurses.h to do fancy console animation using timers. This can be fun and may provide some insight. You will also need to read keyboard input to increase/decrease speed.


Get "Advanced Programming in the Unix Environment" by W. Richard Stevens. The lectures and examples in this book are much more in tune, more realistic and practical to the type of work that is done in C. They show you the intent and purpose (and to a high the degree the philosophy) of the language.

That, IMO, will be better for brushing up your C (in addition to revisiting the oldie-but-goldie K&R book.)

I strongly recommend you go this route (in particular if you are coming from a UI, object-oriented world.) One world of caution: Do not try to do OO in C. It can be done, but that is not your immediate purpose. Learn how to code and model procedurally in C (in particular with examples tuned to its intended purpose.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜