I'm trying to use strcpy in order to put a string in an array of strings. This is my definiton of the arrays:
char movies[10][150], movie[150];
int i = 0, j = 0;
currentChar = getchar();
while(currentChar != EOF)
{
while(currentChar!='\n')
{
movie[i] = currentChar;
currentChar = getchar();
i++;
}
strcpy(*(movies + j*10*15), (char*)movie);
j++;
currentChar = getchar();
}
Trying to debug it in c++ console, I get a 'Buffer is too small' message.
note: My input is "Django unshaved:a bit bloody, but overall a solid film" which does not exceed the 150 chars.
thanks for helping.
edit: code edited to show full picture
*(movies + j)?movies[j][0]is only a single character. You wantmovies[j], which is a buffer of 150 chars. The first index points to your string/film title in the string array, the second index points to characters in that string. (If it isn't beyond the terminating null, that is.)