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 ?
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
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
works perfectly.... thanks a lot... and sorry for replying late, I'm in the college just for attendance πianoopThats 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-#
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 KumarI think your program is like this
#include
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.int main() { printf(βHello World\nβ); return 0; } -
[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#-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:
after searching on internet, I realized that I need to add #includebut that won't work... not sure what I'm doing wrong...π -
[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 KumarIn line: printf ("The answer is %d", &ans);
are you scanning again?? it should be like this
printf ("The answer is %d", ans); -
ErAnushka
Thanks a bunch, I got this now π[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); -
ErAnushka
I thought writing "&" will calculate the answer πianoopIn line: printf ("The answer is %d", &ans);
are you scanning again?? it should be like this
printf ("The answer is %d", ans);
Just removed it, it's working fine now π Thanks π -
[Prototype]
Writing "&" passes the address of the variable..πErAnushkaI thought writing "&" will calculate the answer π
Just removed it, it's working fine now π Thanks π
You can as well send private message to me regarding the small errors..π -
ErAnushka
Okay π[Prototype]Writing "&" passes the address of the variable..π
You can as well send private message to me regarding the small errors..π -
rahul69In TCC "void main()" works fineπ
-
ErAnushka
I'm using int main (void) πrahul69In TCC "void main()" works fineπ -
Neeraj Sharma
It works fine but its always advisable to go with int main()rahul69In TCC "void main()" works fineπ -
KenJackson
Here's my version. There's a big difference. I put all the inputs on the command line.ErAnushkaI made another program for addition of two numbers:
#include
int main (void)
{
...
ans = no1 + no2;
printf ("The answer is %d", &ans);
getch();
return(0);
}
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
Okay πNick_SharmaIt works fine but its always advisable to go with int main() -
ErAnushkaKenJacksonHere'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
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.ErAnushkaI don't know why you've used int main(int argc, char *argv[]) it's totally new to me
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. -
ErAnushkaKenJacksonThat'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
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...ErAnushkaYes, 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 π -
ErAnushka
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 πNick_SharmaProgramming 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... -
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#-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#-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#-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,...