You are here:

C++/beginning with C-please useful

Advertisement


Question
hello.i am from greece and i just started the C language in my university, so i would only like to ask you some simple questions!
1)supposing i write my program in dev-c++,(for example a program that writes to the screen the phrase hello world) then i press the compile button and the execute button, but nothing appears because everything happens so quickly! they told us to write the command system("pause")!Where sould i write this command and what should i do next?
2)another teacher told us to write the "setchar" command and then execute the program through the CMD prompt in windows. what exactly is that?
3)if i write the program in dev-c++ but i want to compile it in cygwin, shoule i save my program with a different name? or what sould i do?
4)everyone teaches us the command cc myprogram.c in order to compile a program!but in dev-c++ there is only a compile button!that means that here i don't need to use the cc.. command? where is it used? and where can i write that?
Any information would be useful, because i just started, and i find it pretty difficult..thanks in advance!

Answer
Hello maki, thank you for the question.

1. You would put the system("pause") right before you returned from your main function. I never really liked system("pause"), so I'll show a better function. If you include <Windows.h> in your program you can use a function called Sleep. It takes a number of milliseconds as a parameter, and pauses the system for that number. So:

#include <Windows.h>

int main()
{
printf("Hello World\n");

Sleep(2000);

return 0;
}

Would give you 2 seconds to view the message in the console box.

2. I have no clue.

3. Saving your program under a different name should not be necessary. Granted, I've never used the cygwin compiler, but it should work like all the rest of them. You open your command prompt and change directories to the file with all your .c files in it, and then run the command that cygwin uses to execute its build process.

4. From your context, it looks like the cc command is used to build a program from the command line. If you are using a compiler with some kind of interface, then it looks like the command line stuff would be unnecessary.

Good luck with programming in C!

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.