I've read that a string always has to be NULL terminated, so I decided to fool around a little with it.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char naam[20];
int x;
printf("Voer naam in: ");
scanf("%20s", &naam);
if (strlen(naam) > 19)
{
printf("String te lang (max 20).. hij zal ingekort worden.\n\n");
}
for (x = 0; x <= 20; x++)
{
printf("karakter %d: %c\n", x, naam[x]);
}
naam[20] = 'd';
for (x = 0; x <= 20; x++)
{
printf("karakter %d: %c\n", x, naam[x]);
}
printf("naam: %s", naam);
}
as you can see naam[20] is filled with d at the end, why is that accepted, now theres now the string isn't terminated, isnt this potentialy dangerous?
I dunno maybe Im just talking bull$$$$ & newbie like, but im curious.
thanx