Which program I should use for "C" programming?

Hello again πŸ˜€ I'm using "codeblocks" for "c" programming. But I don't think it's a great program for learning the basics of "C".
Do you have anyother program for "C" ?
If allowed, anyone can upload TCC? I think we're using that in our college computers.

I'm asking this because, I've seen one tutorial with getch() function. we write this at the end so the program will wait for our input and then only it can close itself.
getch = get character πŸ˜€ (I guess)
There one thing more used, and that is return(0), so many things are there😲
I need to practice these stuff, But I want to use the program that is used in colleges; or similar to that. Anyone can help me please ?

Replies

  • Anoop Kumar
    Anoop Kumar
    getch = get character πŸ˜€ (I guess)
    Thats right.
    Which operating system you are using...
    If windows 7 then it is little bit tricky to install TCC. You need to use DOSBOX.
    #-Link-Snipped-#
  • ErAnushka
    ErAnushka
    ianoop
    Thats right.
    Which operating system you are using...
    If windows 7 then it is little bit tricky to install TCC. You need to use DOSBOX.
    #-Link-Snipped-#
    works perfectly.... thanks a lot... and sorry for replying late, I'm in the college just for attendance πŸ˜€

    I need to know, is that necessary to write return(0) at the end? If I don't write it, I get an error saying that it must return a value or something like that. Why it need to return a value? If I write return(0) at the end, it compile and run without errors.
    So, return(0) is to return a 0 value to the program? I really don't understand.
    And I've to write it in every program?
  • Anoop Kumar
    Anoop Kumar
    I think your program is like this
    #include
    int main()
    {
    printf(β€œHello World\n”);
    return 0;
    }
    here int before main() is expecting to return something from the function main() , That is why a return statement is necessary. It is intrinsic that main() should return a int value.
  • [Prototype]
    [Prototype]
    Its not exactly necessary to return 0, but depending on compiler, it may or may not return the compilation error. GCC doesn't requires that, while it sounds like TCC does requires it.

    Whenever an error occurs, an error code, which is an integer, is returned. Just to ensure that the program has finished successfully & executed till end, we write return 0. That means, if 0 is returned, the program executed till the last line. The TCC as well requires just because a function is expected to return a value. You can write return 123 & it'll work too.

    You can just specify the type of main as void if you don't want to write return 0, but its not recommended since you'll not be able to see if any error occurred since main will not return any error code to the OS.
  • ErAnushka
    ErAnushka
    #-Link-Snipped-# #-Link-Snipped-# Thanks for the info but still I've some questions πŸ˜€

    here is my simple program:

    #include
    int main (void)
    {
    printf ("Hello World");
    getch();
    return(0);
    }

    here, I wrote return(0) which will return a 0 value. We can also write it as "return 0", right?
    But as Prototype said, I can write "return 1" or "return 2" etc.
    So, I think the program should return any value, no matter what it is. Please correct me if I'm wrong πŸ˜€


    I made another program for addition of two numbers:
    #include
    int main (void)
    {
    int no1;
    int no2;
    int ans;

    printf ("enter the value:");

    scanf("%d", &no1);

    printf("enter another value:");

    scanf("%d", &no2);

    ans = no1 + no2;

    printf ("The answer is %d", &ans);

    getch();

    return(0);
    }


    but I got the wrong answer:
    [​IMG]

    after searching on internet, I realized that I need to add #include but that won't work... not sure what I'm doing wrong...πŸ˜•
  • [Prototype]
    [Prototype]
    #-Link-Snipped-#, Yes, you can return anything that you can uniquely identify as successful program execution. Returning 0 has become a tradition because no other error code is 0. It may be possible that you return something like 87234 but its already an error code for some problem. In such case, you won't be able to identify if that code is returned by you or was returned due to error.


    You don't write "&" in printf. It should be like below.

    printf ("The answer is %d", ans);
  • Anoop Kumar
    Anoop Kumar
    In line: printf ("The answer is %d", &ans);
    are you scanning again?? it should be like this
    printf ("The answer is %d", ans);
  • ErAnushka
    ErAnushka
    [Prototype]
    #-Link-Snipped-#, Yes, you can return anything that you can uniquely identify as successful program execution. Returning 0 has become a tradition because no other error code is 0. It may be possible that you return something like 87234 but its already an error code for some problem. In such case, you won't be able to identify if that code is returned by you or was returned due to error.


    You don't write "&" in printf. It should be like below.

    printf ("The answer is %d", ans);
    Thanks a bunch, I got this now πŸ˜€
  • ErAnushka
    ErAnushka
    ianoop
    In line: printf ("The answer is %d", &ans);
    are you scanning again?? it should be like this
    printf ("The answer is %d", ans);
    I thought writing "&" will calculate the answer πŸ˜’
    Just removed it, it's working fine now πŸ˜€ Thanks πŸ˜€
  • [Prototype]
    [Prototype]
    ErAnushka
    I thought writing "&" will calculate the answer πŸ˜’
    Just removed it, it's working fine now πŸ˜€ Thanks πŸ˜€
    Writing "&" passes the address of the variable..πŸ˜€

    You can as well send private message to me regarding the small errors..πŸ˜€
  • ErAnushka
    ErAnushka
    [Prototype]
    Writing "&" passes the address of the variable..πŸ˜€

    You can as well send private message to me regarding the small errors..πŸ˜€
    Okay πŸ˜€
  • rahul69
    rahul69
    In TCC "void main()" works fineπŸ˜€
  • ErAnushka
    ErAnushka
    rahul69
    In TCC "void main()" works fineπŸ˜€
    I'm using int main (void) πŸ˜€
  • Neeraj Sharma
    Neeraj Sharma
    rahul69
    In TCC "void main()" works fineπŸ˜€
    It works fine but its always advisable to go with int main()
  • KenJackson
    KenJackson
    ErAnushka
    I made another program for addition of two numbers:
    #include
    int main (void)
    {
    ...
    ans = no1 + no2;

    printf ("The answer is %d", &ans);

    getch();

    return(0);
    }
    Here's my version. There's a big difference. I put all the inputs on the command line.

    I'm guessing from your use of "getch()" that you are clicking on the executable or the icon of a Windows shortcut. If you do that, it would exit before you could see the answer. So getch() holds the window open until you press a key.

    With my solution, I start with an open command shell (preferably a bash shell--if using Windows I use Cygwin), but a Windows CMD shell would do. So I don't need the final getch().

    #include 
    #include 
    #include 
     
    int main(int argc, char *argv[])
    {
        int error = 0, i, sum;
     
        for (i=1, sum=0;  i
  • ErAnushka
    ErAnushka
    Nick_Sharma
    It works fine but its always advisable to go with int main()
    Okay πŸ˜€
  • ErAnushka
    ErAnushka
    KenJackson
    Here's my version. There's a big difference. I put all the inputs on the command line.

    I'm guessing from your use of "getch()" that you are clicking on the executable or the icon of a Windows shortcut. If you do that, it would exit before you could see the answer. So getch() holds the window open until you press a key.

    With my solution, I start with an open command shell (preferably a bash shell--if using Windows I use Cygwin), but a Windows CMD shell would do. So I don't need the final getch().

    #include 
    #include 
    #include 
     
    int main(int argc, char *argv[])
    {
        int error = 0, i, sum;
     
        for (i=1, sum=0;  i

    I'm just started using C πŸ˜’ I'm not the master but your program looks cool. I don't know why you've used int main(int argc, char *argv[]) it's totally new to me πŸ˜€

    and your program is so different.... [] is used for arrays, I guess.
    I hope I'll make programs like you πŸ˜€
  • KenJackson
    KenJackson
    ErAnushka
    I don't know why you've used int main(int argc, char *argv[]) it's totally new to me
    That's the standard prototype for main(). argc is the number of arguments, plus the command itself, on the command line. argv[] is an array of pointers to the arguments.

    So if you name the resulting executable something imaginative like prog, You could use it like this:
    prog 123 456 789
    Then argc would be 4 and pointers to these 4 strings would be in argv[]: "prog", "123", "456", and "768".

    Pointers and arrays take a little getting used to.
  • ErAnushka
    ErAnushka
    KenJackson
    That's the standard prototype for main(). argc is the number of arguments, plus the command itself, on the command line. argv[] is an array of pointers to the arguments.

    So if you name the resulting executable something imaginative like prog, You could use it like this:
    prog 123 456 789
    Then argc would be 4 and pointers to these 4 strings would be in argv[]: "prog", "123", "456", and "768".

    Pointers and arrays take a little getting used to.

    Yes, I'm learning pointers and arrays πŸ˜€ Once I master it, then only, I can understand what you did in the program πŸ˜€

    One thing I want to ask, computer science and IT both are different branch?
    I can score very well in these branch except programming and electronics stuff 😐
  • Neeraj Sharma
    Neeraj Sharma
    ErAnushka
    Yes, I'm learning pointers and arrays πŸ˜€ Once I master it, then only, I can understand what you did in the program πŸ˜€

    One thing I want to ask, computer science and IT both are different branch?
    I can score very well in these branch except programming and electronics stuff 😐
    Programming is something that matters a lot specially when you are in Computer Science or IT branch. Your interviews for good companies will always be programming-centric So its better to master programing. Your score or percentage only will be important to pass the cut-off filter for appearing in the company but after that its all your programming knowledge and its theoretical base. Its good that you are learning. It will be better that you dedicate this thread completely for your programming preparation. Learn a new concept and write programs here whenever you have doubts or you need explanation. Based on that, I will post one more program and make you understand it. Let's get going...
  • ErAnushka
    ErAnushka
    Nick_Sharma
    Programming is something that matters a lot specially when you are in Computer Science or IT branch. Your interviews for good companies will always be programming-centric So its better to master programing. Your score or percentage only will be important to pass the cut-off filter for appearing in the company but after that its all your programming knowledge and its theoretical base. Its good that you are learning. It will be better that you dedicate this thread completely for your programming preparation. Learn a new concept and write programs here whenever you have doubts or you need explanation. Based on that, I will post one more program and make you understand it. Let's get going...
    I'm in civil branch πŸ˜€ I'm preparing CPU subject. but it would be awesome if you share some useful info which is rarely available on any books πŸ˜€
  • Vishal Sharma
    Vishal Sharma
    I thought writing "&" will calculate the answer
    actually "&" means the "address" or more technically, you can call it as "memory address"
    printf() just needs values to output them
    whereas, scanf() needs to store the values hence we provide "memory address" that is "&" to store the value at a memory location.
  • Vishal Sharma
    Vishal Sharma
    #-Link-Snipped-#
    In TCC "void main()" works fine
    Using void main() is a bad practice of programming. Majority of lecturers use void main() while teaching the programs, but it is a bad practice as you will never know what value your program returns (it takes a garbage return which varies each time you execute the program) Hence it is advisable to use int main()
  • Vishal Sharma
    Vishal Sharma
    #-Link-Snipped-#

    but it would be awesome if you share some useful info which is rarely available on any books
    As you are just a starter in C, I'd suggest you to go with your course book. In that way you'll easily make your basics strong. And after that you can go for other books or take useful info from anyone of us!!
  • ErAnushka
    ErAnushka
    #-Link-Snipped-# thank you for the info πŸ˜€ especially about the "&" πŸ˜€

You are reading an archived discussion.

Related Posts

Hello, this is Jerry - an Instrumentation engineer from Burma. Somebody here knows what coriolis effect is? In physics, the Coriolis effect is a deflection of moving objects when they...
Pradeep Prabhu and Prasanna Raghavendra, the former top guns at Infosys have ventured into CloudMunch.In to offer their cloud platform as a service for businesses focused on software products and...
what are possibility's of new innovations over electrical and electronics and engineering???can you also suggest which more suitable private or government sector for an EE engineer ???thank you in advance
I am a mech engineer and I've this crazy question stuck in mind that I want answered. What is the difference between steam and vapour? Aren't their properties just the...
CEans, Community boards like ours aren't new to spam and spammers. A popular community always attracts spammers like sugar-cube attracts flies. We found out that in the last 2-3 days,...