Note: don't worry if you can't finish the entire lab exercise. Use turnin (see step 15) to turn in as much as you've completed before you leave the lab. Make sure you finish the rest of the lab on your own time.
click Start --> All Programs --> Utilities --> XWin32 8.0 --> XWin32XWin32 is a terminal application for Windows computers, which allows Windows users to connect to Unix servers on a local network or via the Internet. X applications running on those servers will be displayed onto the Windows desktop. There are two reasons why we run XWin32 when connecting to Unix:
Note that C source files cannot be created with word-processing applications (like Microsoft Word) that embed formatting information in the files. You must use an editor like emacs (or pico) that produces straight ASCII text files.
/* Lab 1
Data types
*/
#include <stdio.h>
int main()
{
/* declarations */
int int1, int2, int3;
float f1=1.0, f2=2.5, f3=5.0, f4;
double d1, d2;
char ch1, ch2;
printf ("float f1=%f, f2=%f, f3=%f\n", f1, f2, f3);
int1 = 5;
d2 = 5.0;
ch1 = '5';
printf ("int int1=%d, double d2=%f, char ch1=%c\n", int1, d2, ch1);
int3 = f2;
int2 = int1/int3;
f4 = int1/int3;
printf ("int int3=%d, int2=%d, float f4=%f\n", int3, int2, f4);
d1 = f3 - -f1 * 6 / int3 + 8.0 * (int1 - d2);
printf ("double d1=%f\n", d1);
ch2 = ch1 - 2;
int3 = 'a' - 'A';
ch1 = 'W' + int3;
printf ("char ch2=%c, ch1=%c, int3=%d\n", ch2, ch1, int3);
printf ("enter an integer between 65 and 90: ");
scanf ("%d", &int3);
printf ("that number is the ASCII code for the character %c\n", int3);
return 0;
}
Save the file.
lab1.c: In function 'main': lab1.c:15: error: parse error before "printf"The 15 refers to line 15 in your source file (if you go to the emacs window and click on the first printf statement in the program, you will see L15 displayed at the bottom of the window, telling you the cursor is on line 15). Line 15 is actually syntactically correct. The error occurs a couple of lines above, but it wasn't until the compiler started working on line 15 that it detected a problem. This happens frequently. If the compiler tells you it found an error on a particular line, but you are sure that there are no errors on that line, then search for the error on the lines above the flagged line (start with the line immediately preceeding the flagged line and work backwards). Put the semicolon back where it belongs and recompile.
/cs/bin/turnin submit cs2301 lab1 lab1.c
See you next week!