SETTING UP MSOE LAPTOPS FOR WINDOWS C CONSOLE APP
DEVELOPMENT
Microsoft Windows does not install a C development environment by
default. However, configuring MSOE laptops for development is
quite easy.
Microsoft Visual Studio provides a complete integrated
development environment for applications that run within the
Windows frameworks as well as applications that run from the
command prompt. While Visual Studio is an excellent environment,
it's complexity can be much to learn when simple applications are
all you desire to create. Luckily, Visual Studio also installs a
full set of command line tools so that applications can be
created outside of the more complex integrated development
environment. Use this process to configure your
laptop for quick-and-easy console application development. You
must be on the MSOE domain to follow this instruction set.
Consult with the IT Help Desk if you have imaged
your laptop on your own and need to have your laptop attached to
the domain.
- Install Microsoft Visual Studio 2013 from
the MSOE Domain Add/Remove Programs packages.
- Install Textpad from the MSOE Domain
Add/Remove Programs packages.
- Drill down into Start-Program Files-Visual
Studio-Visual Studio Tools.
- Right-click on "Developer Command Prompt
for VS2013" and pin it to your Taskbar or Start Menu.
DEVELOPING CONSOLE APPLICATIONS PART 1: EDITING
- Click the Developer Command Prompt that you
pinned to your Taskbar or Start Menu.
- Type "d:" at the command prompt to move from
the C: partition to the D: partition.
- Type "cd d:\" at the command prompt to move to
the top folder level of your D: partition.
- Type "dir" at the command prompt to see
files visible at the top folder level of your D: partition.
- Type "mkdir ce2811-win" at the command prompt to
make a folder for ce2811 Windows command prompt program projects
at the top folder level of your D: partition.
- Type "dir" at the command prompt to verify
that the new folder was created.
- Type "cd ce2811-win" to move into the new
project folder. You can also use tab completion when typing these
commands. Type "cd ce28" and hit tab to finish out the typing for
you!
- Make a new directory for a "HelloWorld"
project. Remember how? Hint: mkdir
- Move into the new directory. Remember how?
Hint: cd
- Note that the command prompt window always
shows you where you are in the file folder hierarchy. Your
command prompt window probably says "D:\ce2811-win\HelloWorld" or
something similar to that!
- Type "start textpad main.c" to start the
textpad editor on a file called main.c. Textpad will ask you if
you want to create "new" files or simply open the file if it
already exists. Syntax highlighting is on by default.
- Enter this HelloWorld program that uses
command line arguments. Hint: Consider copy-paste from the
browser to the editor.
HelloWorld Project main.c
/* filename: main.c
* project: HelloWorld
* author: meier@msoe.edu (Dr. M.)
* to use: hello [namestring] [spanish english french chinese]
* arguments:
* - optional namestring
* - optional language
*/
// include library functions
// - stdio: printf
// - string: strcmp
#include <stdio.h>
#include <string.h>
// declare user enum type for language
typedef
enum languages {english, spanish, french, chinese} language;
// main
int main(int argc, char** argv)
{
// process command line arguments
// check for language: default to english
language outputLanguage = english;
if(argc == 3)
{
if(strcmp("spanish",argv[2])==0) outputLanguage = spanish;
else if(strcmp("french",argv[2])==0) outputLanguage = french;
else if(strcmp("chinese",argv[2])==0) outputLanguage = chinese;
}
// do output
switch(outputLanguage)
{
case spanish:
printf("\nHola %s!\a\n",argc>1?argv[1]:"");
break;
case french:
printf("\nBon Jour %s!\a\a\n",argc>1?argv[1]:"");
break;
case chinese:
printf("\nNi Hao %s!\a\a\a\n",argc>1?argv[1]:"");
break;
default:
printf("\nHello %s!\n",argc>1?argv[1]:"");
break;
}
return 0;
}
DEVELOPING CONSOLE APPLICATIONS PART 2: COMPILING
- Save the file using the TextPad save icon,
File-Save, or Ctrl-S keyboard shortcut.
- Switch to the command window.
- Type "cl main.c" to compile and link the
main.c file into a Windows console executable.
- Correct programming errors and repeat
as necessary.
- Run the executable with differenct
parameters:
- Type "main" and hit the
"enter" key. The program should say hello.
- Type "main name" where name is your name.
Now the program will personalize your message in English.
- Type main name spanish" where name is your
name. The program will personalize the message in Spanish.
- Try other languages defined in the C enum as
well as languages that are not defined in the enum.
- Enjoy!