Reputation: 49
(gdb) break main
Breakpoint 1 at 0x722: file homework1.c, line 4.
(gdb) run
Starting program: /home/aj_the_kid/ECE_373/homework1
Breakpoint 1, main () at homework1.c:4
4 {
(gdb) step
8 printf("Enter the temperature (for conversion) in Fahrenheit: ");
(gdb) step
__printf (
format=0x555555554838 "Enter the temperature (for conversion) in Fahrenheit: ") at printf.c:28
28 printf.c: No such file or directory.
(gdb) bt
#0 __printf (
format=0x555555554838 "Enter the temperature (for conversion) in Fahrenheit: ") at printf.c:28
#1 0x0000555555554742 in main () at homework1.c:8
(gdb) next
32 in printf.c
(gdb) next
33 in printf.c
(gdb) step
_IO_vfprintf_internal (s=0x7ffff7dd0760 <_IO_2_1_stdout_>,
format=0x555555554838 "Enter the temperature (for conversion) in Fahrenheit: ", ap=ap@entry=0x7fffffffde20) at vfprintf.c:1244
1244 vfprintf.c: No such file or directory.
(gdb) step
1275 in vfprintf.c
#include <stdio.h>
int main()
{
float temp_F, temp_C;
// Prompt user for input (i.e. temp in Fahrenheit)
printf("Enter the temperature (for conversion) in Fahrenheit: ");
scanf("%f\n", &temp_F);
// Convert F to C
temp_C = (temp_F - 32) * (5/9);
printf("The temperature in Celsius is: %.2f\n", temp_C);
return 0;
}
But I am still getting the issue where it requires me to input the degrees in Fahrenheit again in an empty line like it didnt capture the user input the first time
Terminal View
aj_the_kid@AJs-Sandbox:~/ECE_373$ rm file1
aj_the_kid@AJs-Sandbox:~/ECE_373$ gcc -g -o file1 file1.c
aj_the_kid@AJs-Sandbox:~/ECE_373$ ./file1
Enter the temperature (for conversion) in Fahrenheit: 32
32
The temperature in celcius is: 0.00
aj_the_kid@AJs-Sandbox:~/ECE_373$
Upvotes: 2
Views: 5483
Reputation: 34839
From the comments:
The error message from gdb vfprintf.c: No such file or directory
is due to the fact that you're trying to step into a library function for which you don't have source code.
The problem in the calculation is that the division (5/9)
is performed as integer division. So the result is 0. This can be fixed by changing to (5.0/9.0)
And the scanf
problem is due to the \n
at the end of the format string. scanf
is a little strange about whitespace. Putting the \n
at the end of the format string tells scanf to skip all whitespace until the user types non-whitespace character and presses enter. You can fix it by removing the \n
Upvotes: 2