#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STRING_LENGTH 20
#define MAX 30
int read_string(char string[], int n);
int main(){
int i = 0;
char *name_list[MAX];
char word[STRING_LENGTH + 1];
for (;; i++){
printf("Enter a word.\n");
read_string(word, STRING_LENGTH);
if (word[i] == '\0')
break;
name_list[i] = malloc(sizeof(char) * 20);
strcat(name_list[i], word);
}
}
int read_string(char string[], int n){
int ch, i = 0;
while ((ch = getchar()) != '\n')
if (i < n)
string[i++] = ch;
string[i] = '\0';
return i;
}
The point of this program is to read in words and place them into an array of pointers for sorting. this is what i have so far, my debugger is saying that the use of strcat is unsafe but I do not know why. It says to use strcat_s but that crashes my program. Any help on how to get this working?
for(i=0; i<MAX; i++)