Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

begginer to c programming. whats the procedure?

Options
  • 26-09-2010 1:37pm
    #1
    Registered Users Posts: 1,267 ✭✭✭


    Hi i just started and it degree in IT and im trying to get to grips wih c programming for the first time. Im picking up some parts and terminolgy but im just still unsure about the overall procedure of programming.
    Whats the first thing i do?
    A lot of the tutorials describe some things but id like it in laymans terms .
    in the first lecture we learned about data types and from what i gather after putting

    "main()"
    after the above do i then define the data type of the function such as
    int or float or char and then the function name.

    can someone in laymans terms expalin what is main? what is a function? what are headers and when are they used?
    and ultimately try to detail the procedure of where i start when programming?
    Im probably confused and incorrect fromwhat ive wrote above but if anyone can help id appreciate it.
    Thanks


Comments

  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    C is a procedural language.

    The int main(int argc, char * argv[]) method is the standard entry point of a C program. This is what gets run first when you execute an executable.

    In there you can define data types and structures. You can call user defined or system defined function.

    A user defined function is simply a block of code that you would wish to repeat so you only write it once.

    A function has input parameters passed as arguments to the function and it has a return type.

    To be honest, you are better off reading a getting started book in C. It should become a lot more clear then.

    I'm not sure if you should be starting with C as a language when you don't understand basic concepts. Maybe you should try something a little more forgiving like PHP to get started with. Then once you get the general concept of variables/functions/loops/if statements etc, then move to C.

    C is a difficult language to start with.


  • Registered Users Posts: 1,267 ✭✭✭lightspeed


    ok thanks itsa bsc in it in dit and in the first lecture of programming we just jump right into this which for me is a bit daunting . i kind of thought there would be more explaniation on basic concepts as to just vague terminology and jumping right into compiling.
    thanks for the help though imight look into php so and see if it helps establish the basics for me.
    Thanks


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Ah okay, so straight into C in first year. Can be a bit daunting alright no doubt.

    Maybe the lecturer is trying to teach by example. Give you a basic hello world and tell you what ever thing is?

    There are plenty books on C programming for beginners anyways. I can't recommend any myself. There are plenty online tutorials as well.

    Try starting from here: http://www.cprogramming.com/tutorial/c/lesson1.html


  • Closed Accounts Posts: 6,718 ✭✭✭SkepticOne


    lightspeed, I think the best way to begin is to start typing in very basic programs such as helloworld.c and then gradually introduce other concepts like headers and functions. At each stage observe what the program is doing and how whatever change you make has an impact on the running of the program.

    The tutorial here seems OK. The only thing you have to be careful of is that the methods of compiling and running vary from system to system. In this one you compile by typing

    gcc hello.c

    Other systems will differ in their method of compiling and you need to find out what that is, but otherwise things should be pretty much the same at the starting level. The important thing is that each concept should be tried out by you so you can see what is going on for yourself.

    Have you done your first "Hello World" program?
    #include < stdio.h>
    
    void main()
    {
        printf("\nHello World\n");
    }
    


  • Registered Users Posts: 1,267 ✭✭✭lightspeed


    hi no ive not tried the compiler myself yet as i wanted to figure out what the terminolgy and procedure and reasoning behind doing what im doing.
    perhaps now i should have it open and compile something.
    In the mean time the lecturer gave us some exercise to do and so can anybody here figure them out and explain them to me?
    I know i need to know for myself and tomorrow there is a lab class where i they will show us how the answers and where we can compile on the computers in the college.
    anyways heres most of teh exercises i need help with. i think i have an idea buts im not really sure i fully understand the questions and how they are written.


    2.Write a variable definition for each of the following:
    (a) integer variables number_of_transactions and age_in_years
    (b) floating-point variables total_pay, tax_payment, distance and average
    (c) a character variable account_type
    (d) a double variable gross_pay.

    3.Which of the following are valid variable definitions?

    (a) integer account_code ;
    (b) float balance ;
    (c) decimal total ;
    (d) int age ;
    (e) char int ;

    In the case of an invalid declaration, write a correct declaration.

    4. Write a program to assign values to each of the variables in Q3 and display those values


  • Advertisement
  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    you need to go back through the book first chapter (you said you're in DIT so I'm assuming you're using Paul Kelly's A Guide To C Programming).

    the answers are there. most here could answer them for you in about 5 minutes but you won't learn anything from that.

    i'll give you some hints.

    question 2, practically gives you the answers in the sentences, break them down to variable declarations.

    question 3, is testing your knowledge of valid variable types and valid variable names.

    question 4, once question 3 is done is just testing your knowledge of the printf() function.


  • Registered Users Posts: 2,781 ✭✭✭amen


    C is a difficult language to start with.
    but it is a good one and not that bad.

    Better to understand pointers, memory allocation etc even if you never have to use them in newer languages like java, c# etc.

    At least that way you know what is going on under the hood


  • Registered Users Posts: 40,038 ✭✭✭✭Sparks


    Yup, it's not a bad language to start with. Python might have been friendlier, Pascal would have been better, and anyone starting a student off with PHP or Perl is just being sadistic, but C is a good enough starting point.

    I don't, to be honest, think that the Guide for Dummies kind of book is a good idea with C though. In fact, K&R is about the best book I can think of off the top of my head for learning C. Yes, it's a steep learning curve; it's C. The curve won't change no matter what book you read.


Advertisement