Fair warning, I am quite new to C, and am still very much a beginner with the language. This problem has stuck with me for a while and I thought someone here might be able to help.
Here is the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old \n", age);
double gpa;
printf("Enter your GPA: ");
scanf("%lf", &gpa);
printf("You're GPA is %lf \n", gpa);
char name[20];
printf("Please enter your name: ");
scanf("%s", &name);
printf("Your name is %s \n", name);
char grade;
printf("Enter your grade: ");
scanf("%s", &grade);
printf("Your grade it %s \n ", grade);
return 0;
}
The problem lies in the 'grade' section, everything else works perfectly. The output of the program with user input is
Enter your age: 3
You are 3 years old
Enter your GPA: 4.5
You're GPA is 4.500000
Please enter your name: Test
Your name is Test
Enter your grade: B
Segmentation fault (core dumped)
Hopefully someone here can help. All the best!