1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marrrta [24]
3 years ago
6

Segmentation Faults Recall what causes segmentation fault and bus errors from lecture. Common cause is an invalid pointer or add

ress that is being dereferenced by the C program. Use the program average.c from the assignment page for this exercise. The program is intended to find the average of all the numbers inputted by the user. Currently, it has a bus error if the input exceeds one number. Load average.c into gdb with all the appropriate information and run it. Gdb will trap on the segmentation fault and give you back the prompt. First find where the program execution ended by using backtrace (bt as shortcut) which will print out a stack trace. Find the exact line that caused the segmentation fault.
Q13. What line caused the segmentation fault?
Q14. How do you fix the line so it works properly?
You can recompile the code and run the program again. The program now reads all the input values but the average calculated is still incorrect. Use gdb to fix the program by looking at the output of read_values. To do this, either set a breakpoint using the line number or set a breakpoint in the read_values function. Then continue executing to the end of the function and view the values being returned. (To run until the end of the current function, use the finish command).
Q15. What is the bug? How do you fix it?
//average.c
#include
/*
Read a set of values from the user.
Store the sum in the sum variable and return the number of values
read.
*/
int read_values(double sum) {
int values=0,input=0;
sum = 0;
printf("Enter input values (enter 0 to finish):\n");
scanf("%d",&input);
while(input != 0) {
values++;
sum += input;
scanf("%d",input);
}
return values;
}
int main() {
double sum=0;
int values;
values = read_values(sum);
printf("Average: %g\n",sum/values);
return 0;
}
Computers and Technology
1 answer:
vfiekz [6]3 years ago
8 0

Answer:

See Explanation

Explanation:

Q13. Line that caused the segmentation fault?

The segmentation fault was caused by line 15 i.e. scanf("%d",input);

Q14. How the line was fixed?

The reason for the segmentation fault is that the instruction to get input from the user into the integer variable "input" was not done correctly.

The correction to this is to modify scanf("d",input) to scanf("%d",input);

Q15. The bug?

The bug is that the method needs to return two value; the sum of the inputted numbers and the count of the inputted numbers.

However. it only returns the count of the inputted number.

So, the average is calculated as: 0/count, which will always be 0

How it was fixed?

First, change the method definition to: void and also include an array as one of its parameters.

<em>void read_values(double sum, double arr []) {</em>

Next:

<em>assign sum to arr[0] and values to arr[1]</em>

<em />

In the main method:

Declare an array variable: double arr [2];

Call the read_values function using: read_values(sum,arr);

Get the sum and values using:

<em>sum = arr[0];</em>

<em>values = arr[1];</em>

<em />

Lastly, calculate and print average:

<em>printf("Average: %g\n",sum/values);</em>

See attachment for complete modified program

Download txt
You might be interested in
How do i delete cookies on a chromebook?
Sphinxa [80]

Answer:

Just go into the browser then go to the searchbar go to any website then click the lock icon in the searchbar then click cookies then go from there

Also you can look this simple info up on g0ogle

6 0
3 years ago
Explain why you will do these prarticular things when driving
VashaNatasha [74]
What things?????? Are u talking about
4 0
4 years ago
package dataStructures; /** * Class OrderedLinkedList. * * This class functions as a linked list, but ensures items are stored i
valkas [14]

Answer:

?

Explanation:

8 0
4 years ago
1. Which is a drawback of point-and shoot cameras?
andrezito [222]
1. D you can't change the lens. Point and shoot cameras have a fixed lens so you don't need to change them.

2. C D-SLR. They have fast shutter and focus speeds for photography. They are used in a lot of professional settings. 
6 0
3 years ago
Which digital cellular standard is used widely throughout the world except the united states?
Art [367]

Global System for Mobility (GSM) is a digital cellular standard that is extensively adopted outside of the United States.

<h3>What characteristics does a digital cellular system have?</h3>
  • Any cellular phone system that utilizes digital is a digital cellular system (e.g. TDMA, GSM, CDMA).
  • Synonyms. Increased capacity and security are two benefits of digital cellular technologies over analog cellular networks.
  • More channels in the same analog cellular bandwidth are available with technology options like TDMA and CDMA, along with encrypted voice and data.
  • Caller ID, call forwarding, and three-way calling are among the functions available on digital cellular devices.
  • A large number of the handsets also include integrated liquid crystal displays for paging, long battery lives, and short message services.

Hence the correct answer is  A) GSM

The complete question is:

Which digital cellular standard is used widely throughout the world except the United States?

1. A) GSM

2. B) CDMA

3. C) WLAN

4. D) LTD

5. E) 4G

To learn more about digital cellular, refer to:

brainly.com/question/26307469

#SPJ4

8 0
2 years ago
Other questions:
  • Copying and pasting from the internet can be done without citing the internet page, because everything on the internet is common
    13·1 answer
  • A device that makes it possible for multiple customers to share one address is called a/n _____.
    15·1 answer
  • If you were looking for a record in a very large database and you knew the ID number, which of the following commands would be t
    10·1 answer
  • Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "
    9·1 answer
  • In apersuasive message, opposing ideas should be:
    13·1 answer
  • Mack has started with his first photographic assignment for a magazine. He has clicked around thirty images and uploaded them on
    10·1 answer
  • Why is it so important to adhere to principles that have been put forth by reputable organizations to ensure that you are mainta
    10·1 answer
  • Multitasking systems _____.
    8·1 answer
  • Who does online school on FLVS???????????????????
    9·2 answers
  • Explain with examples what is software​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!