Hi!
the program below is supposed to accept a sentence, and then print out the words in that sentence. the program works fine, but in the end it gives me an error specifying that memory couldn't be read.
do I dismanage my memory here?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int arg, char* argv[]){
char *sentence,words[5][200];
int i = 0;
sentence = (char*) malloc(sizeof(char) * 200);
printf("Please enter your sentence(s):\n");
gets(sentence);
strcpy(words[i] , strtok(sentence," "));
while (words[i]){
puts(words[i]);
i++;
strcpy(words[i] , strtok(NULL," "));
}
system("PAUSE");
return 0;