-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanfFgets.c
More file actions
51 lines (35 loc) · 1.19 KB
/
ScanfFgets.c
File metadata and controls
51 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*@Shyed Shahriar Housaini
Copyright: @uthor*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf(" \n In C \n \n"); /// %s is used for printing string
int age;
printf("Enter your age: \n");
scanf(" %d", &age); /// & is a pointer.
printf("your age: %d \n", age);
double gpa;
printf("Enter your gpa: \n");
scanf(" %lf", &gpa); /// & is a pointer.
printf("your gpa: %f\n", gpa);
char grade;
printf("Enter your grade: \n");
scanf(" %c", &grade); /// & is a pointer.
printf("your grade: %c\n", grade);
char name[19];
///[19] is used to limit the input char number.
printf("Enter your name: \n");
scanf(" %s", name); ///[19] is not needed. For string does not need pointers &
printf("your name: %s\n", name);
printf("but scanf will not take string value after first space.");
printf("So we have to use fgets for only strings, fgets dont get values like int floar double etc.");
;
printf("Enter your name: \n");
char name22[19];
fgets(name22, 19, stdin); ///19 is not needed to limit the input buffer overflow.
///stdin for standard input.
printf("your name: %s named.\n", name22);
/// above code works separately .
return 0;
}