I'm new to programming and I'm stuck on this program which converts Celsius to Fahrenheit. Please help me figure out the problem with my code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
float celsius = atof(argv[1]);
if (argc != 2)
{
printf("Usage: ./fahrenheit <celsius temp>\n");
return 1;
}
float fahrenheit = (celsius * 9) / 5 + 32;
printf("F: %.1f\n", fahrenheit);
}
When I don't pass any argument to the program I get the following error message:
fahrenheit.c:8:26: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/stdlib.h:145:33: note: nonnull attribute specified here
Segmentation fault
Thanks!