i'm curious about one thing. when i write this code it gives unexpected results based on the book i'm reading "The Absolute Beginner's Guide To C (1994)".
in the program i've entered "Geoffrey" and i'm expecting the output to be "Geof" (5 characters including the null zero), but XCode seems to ignore the array length and just prints the entire string (see attached image).
am i doing something wrong, or is the information in this book out of date?
Code:
#include <stdio.h>
main ()
{
char name[5];
printf("Type Your Name: ");
scanf("%s", name);
printf("Your Name is %s", name);
return 0;
}
in the program i've entered "Geoffrey" and i'm expecting the output to be "Geof" (5 characters including the null zero), but XCode seems to ignore the array length and just prints the entire string (see attached image).
am i doing something wrong, or is the information in this book out of date?