Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor edits; reviewed

...

Code Block
bgColor#FFCCCC
langc
#include <stddef.h>
 
enum { ARRAY_SIZE = 32 };
 
void func(void) {
  char dest[ARRAY_SIZE];
  char src[ARRAY_SIZE];
  size_t i;
 
  for (i = 0; src[i] && (i < sizeof(dest)); ++i) {
    dest[i] = src[i];
  }
  dest[i] = '\0';
}

...

Code Block
bgColor#ccccff
langc
#include <stddef.h>
 
enum { ARRAY_SIZE = 32 };
 
void func(void) {
  char dest[ARRAY_SIZE];
  char src[ARRAY_SIZE];
  size_t i;

  for (i = 0; src[i] && (i < sizeof(dest) - 1); ++i) {
    dest[i] = src[i];
  }
  dest[i] = '\0';
}

...

Code Block
bgColor#ccccff
langc
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
 
enum { BUFFERSIZE = 32 };
 
void func(void) {
  char buf[BUFFERSIZE];

  if (gets_s(buf, sizeof(buf)) == NULL) {
    /* Handle error */
  }
}

...

Code Block
bgColor#ffcccc
langc
#include <stdio.h>
 
void get_data(void) {
  enum { BUF_LENGTH = 1024 };
  char buf[BUF_LENGTH];
  fscanf(stdin, "%s", buf); */
  /* rest of function
}

...

Code Block
bgColor#ccccff
langc
#include <stdio.h>
 
void get_data(void) {
  enum { BUF_LENGTH = 1024 };
  char buf[BUF_LENGTH];
  fscanf(stdin, "%1024s", buf);
  /* rest of function */
}

...