Thread: Newbie to C

  1. #1
    Registered User
    Join Date
    Jun 2013

    Newbie to C

    Hi , I just came across this board as I was looking at the example code for a course on C I am taking.I just have few questions?

    How do I write the code for assignment without copying it off the internet and modifying it or even looking at other codes.

    What I mean to say is how do I write a full program from scratch with just given instructions.

    I have seen many people program without even looking at any other codes and I want to be like them but often times I don't get it at all.

    How should I develop a full logic for the program with just given question?

    If anybody can help it would be great.

    Also, is there any site where I can practice c problem that range from easy to hard?

  2. #2
    Registered User
    Join Date
    Sep 2006
    You have to first grasp the basics of C. There is a link to the C Tutorial at the top of this forum - CLICK IT - and I guarantee you'll will learn TONS of useful C.

    To get this grasp of C, you MUST look at code from others. It's like learning any foreign language, you MUST speak it, you MUST hear it. You can't just read up on an analysis of it's phonic and linguistic structure, and learn to speak a foreign language.

    Say you were given an assignment to write a program that finds the least valued coin in a pile of 25 coins, and the greatest valued coin, as well.

    How would YOU (no computer), do it? Go through this step SLOWLY by hand, until you know you understand every little tiny step you used to do it.

    It might be:

    *go through the coins one by one

    *the lowest value coin is the first coin I look at

    *the highest value coin is the first coin I look at

    *with every coin I look at I compare it to the lowest coin found so far, and to the highest valued coin found so far.

    *if the coin I'm looking at is less than the lowest valued coin, I assign it as the new lowest valued coin.

    *if the coin I'm looking at is greater than the highest valued coin so far, I assign it as the new highest valued coin.

    *when there are no more coins to look at, I have the final low and high valued coins.

    That makes sense so far, so let's make some pseudo code from the above. Since programming STRONGLY uses loops, I'll rearrange the above, a bit, so a loop becomes more straightforward.
    int lowest = coins[0]
    int highest = coins[0]
    for(each coin from 1 to 24)   //coins[0] is already looked at
       if(coin[i] < lowest)
          lowest equals coin[i]
       if(coin[i] > highest)
          highest equals coin[i]
    end for loop
    print(lowest coin value: %d,   highest coin value: %d",lowest, highest)
    The above is easily translated into a final C program.

    When you "walk" through the exercise, given a problem you can't make a program for, without the computer, nice and slow, you will get a real "light bulb" experience. Maybe after 1 or after 10 times, but you will see the basic logic of what you need to do, that way.

    As far as designing a program, the way I learned it was called Top Down Design. You start with main(), and the functions you will call from main() - maybe input(), computation(), and output(), will be called. Think of each function in well - functional terms.

    AND PUT OFF THE DETAILS (display, file names, output formats, etc.), until last.

    Get the "flow" of the core logic, going correctly. Compile your code after every block of code, to check your syntax. You DON'T want to be left with 100 errors, and 50 warnings, after writing a lot of code!

    Once a function is finished, be sure to check it over "around the extreme edges" especially, to see if it's OK.

    When you've finished the rough program, now fill in all the details you put off.

    Learn to use the debugger for your compiler. Huge help for stepping through the program. Probably most commonly, a few simple statements like this, are very helpful, when debugging.

    printf("lowest: %d  highest %d \n",lowest, highest); getchar();
    Where lowest and highest are the variables whose value is in question.

    And do program a lot. Nothing can replace your practice of the craft - learning about your compiler, it's warnings, your help from the user interface, the various headers in C, and the functions they have that are so VERY helpful, etc.

    If you don't program for several weeks or months, you will be surprised at how much your C skills will have eroded away.

    Like any other acquired skill.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello, I am a newbie and so I have a newbie question;)
    By piratemonkey247 in forum C Programming
    Replies: 4
    Last Post: 12-20-2012, 10:59 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. For a Newbie, 2.0 or 1.1?
    By Zeusbwr in forum C# Programming
    Replies: 27
    Last Post: 04-21-2005, 03:18 PM
  4. Okay, newbie right here
    By SkyHi in forum C++ Programming
    Replies: 7
    Last Post: 04-21-2005, 10:47 AM
  5. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM

Tags for this Thread