Tested the use of sizeof
This commit is contained in:
parent
3d602be8f5
commit
624a784be7
12
misc/sizes.c
Normal file
12
misc/sizes.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
char c[20];
|
||||||
|
printf("%d %d", sizeof(a), sizeof(c));
|
||||||
|
|
||||||
|
b = sizeof(c);
|
||||||
|
printf("\n%d\n", b);
|
||||||
|
}
|
29
vagen_till_c/ch2/text2_safe_functions.c
Normal file
29
vagen_till_c/ch2/text2_safe_functions.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void readline(int s, char line[])
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
int i;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
while (( c = getchar()) != '\n')
|
||||||
|
{
|
||||||
|
line[i] = c;
|
||||||
|
i++;
|
||||||
|
if (i >= s-1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char name[20];
|
||||||
|
int size;
|
||||||
|
size = sizeof(name);
|
||||||
|
printf("Enter your name: ");
|
||||||
|
readline(size, name);
|
||||||
|
printf("Hello %s\n", name);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user