Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: C programmers

  1. #11
    Join Date
    Jun 2008
    Location
    Bangalore, India
    Posts
    53

    Default

    Quote Originally Posted by pvbinu View Post
    start programming with simpler languages like basic,foxpro rather than C
    if some people feel it is hard it doesn't mean that others are same... so please don't discourage others...

    C is simple language, if you think it is easy (psychological nature). Same way if you think basic or foxpro are hard it will be hard...

  2. #12
    Join Date
    Dec 2009
    Posts
    4

    Default

    it is between c# and asm, like c++ without the oop

  3. #13
    Join Date
    Aug 2010
    Posts
    5

    Arrow How to be a C programmer - part 1

    Hi Siva

    ok so the following is for people who want to be C programmers. It's of course impossible to master C through a couple of threads in a forum but I hope that you'll get the basics and enough of a grasp to move on from here. I assume you know nothing at all of programming.

    First a bit of theory. Not wanting to be boring but there are some nut and bolts you need to know to see the full picture. A computer program is a system and all systems have the following structure.

    input ---> [ processing ( and possibly storage ) ] ---> output

    Say, a calculator, you type in 2 + 2, that's the input. The calculator decides the answer is 4, that's the processing. The answer 4 is displayed on the screen, that's the output. Programs, whether simple or complicated, are all systems.

    Systems can be made out of subsystems. All subsystems have the same structure (input, processing, output), it's just that one's output will be the other's input. Subsystems in a C program are called functions. Think of functions as bricks to build a house.

    Computers only deal with 0 and 1. So theoretically you should open an editor and type in 0001110010... etc. That would not be practical. That's why we have computer languages like c. However a C program is text, not executable instructions, so a conversion will have to be done. The software doing the conversion is called a compiler. A compiler is itself a system.

    text file containing C program ---> [ compiling ] ---> executable binary file

  4. #14
    Join Date
    Aug 2010
    Posts
    5

    Arrow How to be a C programmer - Part 2

    C is a beautiful language and the single most consistent language ever concieved. That's of course a matter of personal view. It's not the easiest language however. It's what is a called a medium level language. A low level language would be a language like assembly. When programming assembly you write a program that will only be understood by a specifc computer chip (intel, amd, motorola) and deal a lot with technical stuff. So much so that you get very little of practical value done.
    In a high level language (PHP, Python) you (almost) never think of technical issues. You focus on the content of what you are doing. The drawback is that those languages tend to be designed for specific purposes and are more suitable for one purpose rather than another. PHP can only do webprogramming. Perl was originally designed for writing reports.
    C is medium level. You mostly deal with the practical stuff but there are many technical snags that can make you trip up. You just have to know the guts of the machine.

    example

    int result = 7 / 2;

    The answer put into 'result' will be 3, not 3.5 as you might expect. Variables of the type 'int' can only cope with whole numbers.

  5. #15
    Join Date
    Aug 2010
    Posts
    5

    Arrow How to be a C programmer - part 3

    But by now you are burning to actually program. So let's do the traditional 'hello world' program.
    -----------------------------------------------------
    #include "stdio.h"

    void main( ){

    printf("Hello World!\n");

    }

    ---------------------------------------------------------

    That may look all a bit puzzling to a beginner. So let's begin with the beginning. I said that functions were subsystems but the entire program itself is also considered to be a function, it's the main function. It has to be called 'main' so that the compiler would know where the program begins. Since functions are (sub)systems it should not be surprising they have the following structure.

    <type of output> <name of function> ( <type of input> ) {

    <actual code here>

    }

    In our case the type of output was void. Which means 'no specific type of output'. The name is main and in between the brackets there is the input; nothing in this case. The function itself goes from the opening curly bracket till the closing one.
    In between the curly brackets I put printf. That means 'display a bit of text in the terminal'. Printf is itself a function. It was written by someone else, the body of the function is not visible here. It's being called, that means we want to make use of it here. In between the round brackets we put the input. Which is "Hello World!\n". The double quotes is used when dealing with text as opposed to numbers. The '\' means that the next character is not to be taken literally. The 'n' after that means take a new line.
    The body of printf is not in the program but the compiler needs to be able to find it. That's why we write #include. The include tells the compiler we might be using the functions in our program that are described in "stdio.h", like printf.

  6. #16
    Join Date
    Aug 2010
    Posts
    5

    Arrow How to be a C programmer - part 4

    Ok, that's for the very, very basics. Let's do something a bit more complicated. The following program does compute the first 10 Fibonacci numbers. I must admit I didn't compile this so minor errors are a possibility. ( I writing from a cyber cafe so compiling here is not practical.)

    ------------------------------------------------------------------------------------------

    #include "stdio.h"

    // text after these two forward slashes means comment
    // the compiler ignores everything on the line

    /*
    everything inside those symbols
    means comment too
    */

    int fibonacci (int n);

    void main( ){

    int i = 1;
    int j = 0;

    while( i < 11){
    j = fibonacci(i);
    printf("Fibonacci number %d is %d\n", i, j);
    i = i + 1;
    }

    }

    // program to be continued in part 5

  7. #17
    Join Date
    Aug 2010
    Posts
    5

    Arrow How to be a C programmer - part 5

    int fibonacci(int n){

    if ( n <= 0){
    return -1;
    //-1 means ERROR
    }
    if(n == 1 || n == 2){
    return 1;
    }

    int prev = 1;
    int pprev = 1;
    int tmp = 1;
    n = n - 2;

    while(n){
    tmp = pprev;
    pprev = prev;
    prev = prev + tmp;
    n = n - 1;
    }
    return prev;

    }

    ----------------------------------------------------------------------------

    That's a whole lot of stuff so let's comment a small bit. At the very top I wrote:

    int fibonacci( int n);

    That's called the prototype. That's to make the compiler aware that this function will be used during the program. The compiler reads the file from top to bottom. If it finds the function first in the main function it will raise an error and say ' I don't know about that function' or something to that effect.

    int i = 0;

    That means reserve a bit of memory and call it ' i ' and set it to zero. The first word is the type 'int' as in 'integer' means we are going to use ' i ' for whole numbers only.

    Ok so that was a fair bit for today. I will write more tomorrow. Just in case you didn't know the fibonacci sequence is a series of numbers where the next number is the sum of the two previous. It goes:
    1 1 2 3 5 8 etc.

    Cheers
    Gregg

  8. #18
    Join Date
    Oct 2010
    Location
    thailand
    Posts
    7

    Default

    I think it difficult

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •