Thread: practice programs

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    68

    practice programs

    Hey everyone,
    Where can i find practice programs ranging from simple to advanced ,covering each and every topic of c?

    Can some one provide me with some web links,or good book references.


    Also, i am very interested in embeded programming,what sort of approach do i take towards it,i mean which c concepts do i capitalize on?which do/can i ignore etc...
    Thanks,
    ak
    Last edited by ak47; 10-20-2012 at 02:58 AM.

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    68

    making my own customized header file

    I have a program with a list of formulas(area,perimeter,circumference of square,circle,triangle,rombus...and many others)
    I have already made their functions and use them in the same program.

    Is it possible i can have my own header file with all my functions in them.,and use them the same way we use functions in string.h or stdio.h?

    I don't know the exact procedure on how to do it(where do functions go,their prototypes...?)without risking the possibility of messing up the in built library functions.

    I'm using codeblocks(with gcc compiler) if it helps

    Thanks in advance

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    68
    Edit 1:
    Forgive me if i'm not posting all my questions into a single post(the edit option seems to vanish after some time),i am posting the questions as they come when i'm programming.
    1.i've tried for an hour and cannot find a clearing screen function in my compiler library.In dos(turbo c) its clrscr() ,what is its equivalent in a gcc compiler?
    I tried system("clear") ,but getting this error:

    "'clear' is not recognized as an internal or external command,operable program or batch file"
    2.Also is there a replacement for gotoxy() in gcc?
    3.Why is the use of goto() discouraged? i find it quiet useful,saves a lot of loops for me.
    Last edited by ak47; 10-20-2012 at 05:49 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ak47
    Is it possible i can have my own header file with all my functions in them.,and use them the same way we use functions in string.h or stdio.h?
    Yes. Whatever material that you are using to learn C will eventually cover this, if not a search for things like "how to write C header files" will lead you to the answers you seek.

    Quote Originally Posted by ak47
    1.i've tried for an hour and cannot find a clearing screen function in my compiler library.In dos(turbo c) its clrscr() ,what is its equivalent in a gcc compiler?
    I tried system("clear") ,but getting this error:

    "'clear' is not recognized as an internal or external command,operable program or batch file"
    You could read the FAQ on How do I clear the screen?

    Quote Originally Posted by ak47
    3.Why is the use of goto() discouraged? i find it quiet useful,saves a lot of loops for me.
    Considering that loops typically involve hidden gotos, that is unlikely: you probably still have those loops, except that they are expressed as gotos. This makes them harder to identify as common loop structures, hence you should prefer to use the loop constructs rather than goto.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Where can i find practice programs ranging from simple to advanced ,covering each and every topic of c?
    - There are practice problems right here on the main site: C/C++ Programming Practice Problems - Cprogramming.com
    - You can also search through the contest forum for ideas
    - Quite a few threads have been started asking this question, and many good answers were given. Search the forums for them.
    - You can google "c programming practice problems" (be wary of solutions - there is some bad code out there!)

    Also, i am very interested in embeded programming,what sort of approach do i take towards it,i mean which c concepts do i capitalize on?which do/can i ignore etc...
    I'd recommend ignorning nothing. Keep learning all you can - much of the language can be used for embedded programming, but more importantly, you want to hone your skills for syntax, finding references to functions, troubleshooting, etc.

    First learning to program embedded devices can be tough, as there are a lot of things you have to learn/figure out before you can even make an LED blink. Make sure you're good at reading data sheets, which require a good study to properly initialize your device, and to avoid pitfalls. I'd recommend the PIC microchip devices to start with - in my opinion, they're the "friendliest" ones to start with.

    I tried system("clear") ,but getting this error...
    Try:

    Code:
    system("cls");

  6. #6
    Registered User
    Join Date
    Sep 2012
    Posts
    68
    Thank you laserlight and Matticus.Was out of town for a while and could not reply sooner.
    The system("cls") did the trick thankyou.
    I got my customized header running and working as well.
    @Matticus: Do you know any place online where i can buy a MCU(8051 or some other simpler controller) kit to practice on.I have no idea of the specifications and stuff about the board ,that a basic embedded programmer would need!

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Assuming you want to try the PIC microchip parts I referenced...

    Hardware - You can choose a development board with pretty much all necessary parts included; device, crystal [clock], switches/LEDs, programmer (and programming software), etc. Here is a link to the devices listed on the microchip website - note that I haven't evaluated anything on this link, it's just an FYI. More can be found on the big electrical component sites, such as mouser.com, digikey.com, and newark.com.

    Or you can buy the individual parts and put it all together. If you don't have much of an electrical background, then you'd probably be better off getting the development kit. The development kit has the benefit of requiring no other hardware for basic learning.

    Software

    You can download the MPLAB IDE for free at the web site, which requires assembly language to program the device (using a reduced instruction set, defined on the data sheet for the desired device). They also offer a free (albeit limited) 'C' compiler called HI-TECH C (note the limitation of devices that the free version can compile for).

    Must do

    When you select a device or kit, get the data sheet for that device and print it out. It will require much reading and understanding before you can even begin to accomplish the basics. It's not an easy journey, but is infinitely rewarding if this is where your passion lies and you are motivated to learn.

    If you want to stay in the realm familiar with 8051, then just look at the 8-bit devices. Go to the main microchip site and check out the "8-bit PIC MCUs" link. I started learning on the 16F series, and that is a great route for gaining familiarity with MCU programming.

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    The PIC is a very good MCU - Can I recommend

    Product Search - microchipDIRECT

    Also, the "Arduino" is very popular at the moment - You will be surprised what you can make thanks to libraries and break-out boards.

    And I wouldn't be doing you justice if I didn't recommend you have a look into the AVR (what the Arduino is built upon).
    Fact - Beethoven wrote his first symphony in C

  9. #9
    Registered User
    Join Date
    Sep 2012
    Posts
    68
    I'm sticking to PIC,if i probably go any further i'd confuse myself.
    In fact when i heard PIC in this thread for the first time i got it confused with "peripheral interface controller",with the actual brand name of the microchip family.
    I'm in need of a good embedded programming book so that i get the grasp of the basics and take it step by step.Can some one suggest me one?.

    Also I read somewhere(can't remember where) that bit wise operators are used often in embedded programming,so i thought i'd practice programs that use bit wise operators ,but cannot find any such programs/applications.Could some one suggest me a few programs to work with.
    Thanks in advance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 11-09-2009, 07:03 AM
  2. Programs for practice?
    By riwa in forum C Programming
    Replies: 2
    Last Post: 03-10-2009, 10:44 PM
  3. Practice
    By 00Sven in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:13 PM
  4. is it bad practice to....
    By abrege in forum C++ Programming
    Replies: 7
    Last Post: 02-07-2003, 09:03 PM
  5. Bad Practice??
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-25-2001, 08:37 AM