...
Code Block | ||||
---|---|---|---|---|
| ||||
#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 | ||||
---|---|---|---|---|
| ||||
#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 | ||||
---|---|---|---|---|
| ||||
#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 | ||||
---|---|---|---|---|
| ||||
#include <stdio.h>
void get_data(void) {
enum { BUF_LENGTH = 1024 };
char buf[BUF_LENGTH];
fscanf(stdin, "%s", buf); */
/* rest of function
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h>
void get_data(void) {
enum { BUF_LENGTH = 1024 };
char buf[BUF_LENGTH];
fscanf(stdin, "%1024s", buf);
/* rest of function */
}
|
...