Hello, C newbie here...
below is a driver for a pretty simple function which is supposed to read in n chars from input and store in a char array.
#include <stdio.h>
#define SIZE 81
void get_str (char * array, int n) ;
int main (void)
{
char instr [SIZE] ;
printf ("Please enter string for storage:\n") ;
get_str (instr, SIZE) ;
printf ("The first %d characters of the string entered were:\n", SIZE) ;
puts (instr) ;
return 0 ;
}
void get_str (char * array, int n)
{
int count ;
char ch ;
for (count = 0; count < SIZE && (ch = getchar()); count++)
*(array + count) = ch ;
}
I would have expected that this code wouldn't work, because there is no null character stored at the end of the array. However, I tried compiling and running, and it works fine...not that I'm complaining, but why is there no null character needed?
Cheers:)