Thread: Post your beginner/intermediate level C programming exercises here

  1. #16
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    Quote Originally Posted by Salem View Post
    There are plenty of old homework questions posted on this (and many other) forums. How about reading them and seeing if you can do them? Don't bother to post the complete answer, just feel good that you know how to solve it.

    Also google "programming contests". There are sites with lots of problems, and automated checking of your answer.
    Thank you. I found some good ones online from searching programming contests.

    At first, I tried googling programming excercises or programing ideas but nothing good came up. Everything I found was simply going over conepts in the most basic sense. (E.g., create a program that asks the user for 10 integers and then prints those out in reverse order.)
    Last edited by matthayzon89; 09-29-2010 at 09:12 AM.

  2. #17
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    Quote Originally Posted by cyberfish View Post
    Since when has this forum become so hostile?

    Judging by the examples you posted, I'm guessing you like more algorithmically challenging problems?

    If you are a beginner in C they will be a little challenging, but challenges are good .
    Actually, I am not really limited to algorithmically chellenging problems. Anything any of the forum members think would be good practice for any reason, I will try to code sooner or later...


    Im up for the challenge as long as it is nothing too beyond my level of understanding.

    Also, rather than suggesting websites that have practice problems and ideas, I would rather forum members actually recommend a specific programming assignment/ problem that they might have tried that helped them improve their programming skills...

    Thanks for those who actually tried to help, I really appreciate it.
    Last edited by matthayzon89; 09-29-2010 at 09:25 AM.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you want a good and healthy challenge, try writing safe alternatives of strcpy, and anything else that involves arrays of a fixed length.

    Then there are always algorithms to write. Stacks, queues, linked lists, quicksort, heapsort, etc.
    Algorithms are always a little tricky to write (especially generic ones in C), but you can learn a lot.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have an array that only holds 10 names, but you have 20 names in a file, that need to be sorted, and are not in sorted order.

    Using the array, sort the names.
    =========================
    A little strtok() devil:

    You have a file with lines of text (multiple words per line, and not the same number of words per line).

    Paragraphs are double spaced, as per norm.

    Using a two paragraph text selection for your text file, use strtok() to "burst" each word out, into a 2D char array, one word per row of the array.

    =========================
    You want to know how tall your tree has grown over the years.

    Lining up your eye with a fence post that is 6 feet high, you notice that with your eye at 5 1/2 ft. off the ground, the top of the fence post lines up with the top of the tree, when you stand 3 ft away from the fence post.

    The fence post is 20 ft. away from the base of the tree.

    How tall is the tree?
    Last edited by Adak; 09-29-2010 at 11:54 AM.

  5. #20
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I've got one that is slightly trickier for a beginner, but worth a try:

    Implement a simple text-based version of a two player chess game. The board is represented as a 2D array of characters. You have two players taking turns making moves. Display the current situation on the board after every move. If a move is illegal, inform the player and allow him to try again until he makes a legal move.

    If you are really fancy you can implement a text menu for every player to allow the game to be saved and loaded from a file. All you would need to store is the situation on the board and whose turn it is to move.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  6. #21
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Another thing I recommend is to try out some of the simpler problems on the Euler project website.

    If you are learning C it will force you to find various speedups and tricks in your algorithm to give the output in the required time.

    The website can be found here:
    Project Euler
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. Lost on Queues - Help GREATLY appreciated.
    By TetsuoShima in forum C Programming
    Replies: 3
    Last Post: 07-13-2010, 05:35 AM
  3. HTTPS POST with C Socket
    By pobri19 in forum Networking/Device Communication
    Replies: 14
    Last Post: 05-02-2010, 11:21 PM
  4. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  5. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM