Thread: New to C Programming

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    New to C Programming

    Hello, I am starting college on the 23rd and one of my first required classes is Intro to C Programming. I have never done any C Programming. I have done I think 1 or 2 small command-line based programs in C++. I have done an extensive amount of html and php. And I have done a large amount of Java Programming and am currently building Java Programs in an internship with a Low-Cost United States based Airline.

    Since I'm starting C in a few weeks, I just got my book and I wanted to try to get a jump on the class and figure out some of the basics. I wanted to know if anyone had any suggestions for a good IDE for a C Programming Beginner. My preference is something that is not difficult to use and provides some help, but doesnt do the work for me. For those who are familiar with Java Programming, I use JCreator as my IDE because it doesnt do any of the work for me and I get more out of it when I have to do it myself. For my C IDE, I would prefer if it had some sort of Interface Designer so I dont have to worry about hardcoding the Interfaces if I start to build some small applications. As I familiar myself with C, I will look more at hardcoding the Interfaces.

    Any suggestions are appreciated.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    8
    Code::Blocks with mingw. It has a GUI interface, use GNU GCC Compiler and free.

    Code::Blocks

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    Quote Originally Posted by dev123 View Post
    Code::Blocks with mingw. It has a GUI interface, use GNU GCC Compiler and free.

    Code::Blocks
    It claims to be a C++ IDE. Will be it good for C Programming as well, or how does that work?

  4. #4
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    It works as both, put a .c on the end of a file and gcc will treat it as a c file. That's not to say c++ will compile as c, it just means that, for all purposes you'll need to worry about, just use a .c extension and it will be treated as such.

    Also, it should be noted, that CB provides the choice, when creating a project, whether a project is in C or C++. This option only defines the default extension for the files you create, nothing else AFAIK.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    Quote Originally Posted by User Name: View Post
    It works as both, put a .c on the end of a file and gcc will treat it as a c file. That's not to say c++ will compile as c, it just means that, for all purposes you'll need to worry about, just use a .c extension and it will be treated as such.

    Also, it should be noted, that CB provides the choice, when creating a project, whether a project is in C or C++. This option only defines the default extension for the files you create, nothing else AFAIK.
    Thanks, I'll definitely have a look at that this week. I know that C is a language that can take some getting used to, but is there anything in particular that I should be wary of that is an extreme difference from the Object-Oriented Programming Languages? Such as Arrays and working with items with multiple traits (Objects).

    Skimming through my book, I can, for the most part, read and understand what the sample code does without reading the descriptions.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Yes, for example, C doesn't support OOP. Or most of the group of features people refer to as OOP anyways.

    There's no objects (there are structs, which are basically classes where everything is public, and cannot have methods), inheritance, ctors/dtors, polymorphism, etc.

    You will find it quite primitive if you are used to Java.

    C was designed back then when hardware and software are a lot simpler, and OOP didn't make much sense.

    It's relatively "close-to-metal" compared to the languages you know, which can be good or bad depending on what you are trying to do.

    C++ adds, predominantly, OOP features to C, as well as a new standard library (called STL, standard template library) that uses those features, making it superficially a lot more like languages like Java, though still quite a bit lighter.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is one thing. And that is security issues.
    C does not enforce bounds. It is quite possible to write outside arrays bounds causing buffer overruns. To make matters worse, there is no string object. There is only a primitive datatype char to hold a character. An array of those makes a string. But an array has no concept of size.
    So for every function where you use strings and arrays, pass the size, and make sure you don't overrun the buffer.
    The easiest way is to create your custom functions that deals with array to enforce this.

    Aside from that, it lacks pretty much everything else you'd expect. No OOP. No generics. No objects. No runtime type information.
    C is really a bare-bones language to use only in the cases you must, for obvious reasons.
    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.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    Ok, so I grabbed a program in my book and expanded on it to play with some things. It is very basic, just grabs a user input and displays a result. However, I'm kind of happy with this as my first C Program since it only took like 15-20 minutes to understand everything it covers. In this I managed to incorporate loops, constants, importing, user input, output, placeholders in format strings, conditional statements, and arithmetic expressions. Here is the code:
    Code:
    #include <stdio.h>
    #define HEART_BEAT 75
    int
    main(void)
    {
        int heart = 0;
        int diff = 0;
    
        while(heart>=0)
        {
            printf("Enter the heartbeat: ");
            scanf("%d", &heart);
    
            if(heart<0)
                return(0);
    
            if(heart>HEART_BEAT)
            {
                diff = heart - HEART_BEAT;
                if(diff>25)
                    printf("The heart rate is very high. Rate is %d above recommended heart rate.\n\n",diff);
                else
                    printf("The heart rate is high by %d.\n\n",diff);
            }
            else if(heart<HEART_BEAT)
            {
                diff = HEART_BEAT - heart;
                if(diff>25)
                    printf("The heart rate is very low. Rate is %d above recommended heart rate.\n\n",diff);
                else
                    printf("The heart rate is low by %d.\n\n",diff);
            }
            else
                printf("The heart rate is ideal.\n\n");
        }
        return(0);
    }
    What are the thoughts on this? I'm getting a grasp of the basic concepts I skimmed through in the first 6 chapters of my book. Any suggestions as far as expanding this more and how, or if I did anything that is stylistically bad?

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The only thing I saw that was questionable was using the literal 25 instead of a Macro.
    I would do another macro to replace the 25 like you did for HEART_BEAT.

    Note: I do this all the time; I know better than embedding literal values; but, I never seem to have the time to think up logical names for all of them. But, I try never to use the literal values twice without replacing them with a macro.

    Magic number (programming) - Wikipedia, the free encyclopedia
    Other things I try to avoid doing
    Anti-pattern - Wikipedia, the free encyclopedia

    Tim S.

    Code:
    #define HEART_BEAT 75

  10. #10
    Registered User
    Join Date
    Aug 2010
    Posts
    9
    Quote Originally Posted by stahta01 View Post
    The only thing I saw that was questionable was using the literal 25 instead of a Macro.
    I would do another macro to replace the 25 like you did for HEART_BEAT.

    Note: I do this all the time; I know better than embedding literal values; but, I never seem to have the time to think up logical names for all of them. But, I try never to use the literal values twice without replacing them with a macro.

    Magic number (programming) - Wikipedia, the free encyclopedia
    Other things I try to avoid doing
    Anti-pattern - Wikipedia, the free encyclopedia

    Tim S.

    Code:
    #define HEART_BEAT 75
    Ok, I can see why you say that. I never really thought about it before, but when I make Java Programs, to understand a new concept I usually use literal values, but when I have a grasp of them I make them macros or dynamic variables. Not sure why I do that. I think it might be because it makes it easier for me to read through the code manually when I try to review what I did. I guess I just assumed diff would always be compared to 25, but if that ever had to change, it would make it exponentially more difficult to make that change. I have always had an issue not noticing the possibility of dynamic changes in my programs.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    12
    may be it should be "anjuta" IDE or else.

Popular pages Recent additions subscribe to a feed