CS 101
Lab 6

 

This lab is to be worked on individually, but you may feel free to consult with other students.

Objectives

Instructions

Using Eclipse

For this section, please refer to the lecture notes for Lectures 8 ,9 and 10.

Creating a Project

Entering the code

     

Fixing the errors

Running your program

Your program will ask you to enter a number. Type in any number and hit enter.

Write down what happens on your answer sheet.
2. Write what happens when you run your program for the first time after it compiles:

Oops, it looks like we have another problem with our program, and the compiler didn't catch it.

It seemed to happen just after entering the number, so let's look at the line where our program reads the input.

scanf("%i", x);

(Notice that the scanf line is underlined in yellow. Read the warning message by pointing your mouse at the underlined code.)

The problem is that this function expects to be given the location of an integer, but we gave it the integer itself. Since the value of a was zero, the function tried to use memory at location 0, which caused a segmentation fault. (and no output in Eclipse.)

To fix the error, we put a & in front of the variable x.

scanf("%i", &x);

Save and run your program again by clicking the green part of the "Run" Button.

Have the TA initial your answer sheet and check that your programs runs. Show your lab TA the code you entered.

3. TA's initials for Part 1: _______

Congratulations! You have now been initiated into the world of C and Eclipse.

 
  That's it. You're done for Lab 6!