0
Guys, I was testing the function strtok only it is giving this problem of "Segmentation failure (recorded core image)".
Before I tried to do strPtr [i] = strtok (str1, str2); but I made that mistake:
"error: assignment to Expression with array type error"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
char str1[] = "Teste de funcao que separa string em tokens";
char str2[] = " ";
char strPtr[10][10];
char *aux;
int i;
aux = strtok (str1, str2);
strcpy (strPtr[0], aux);
for (i = 1; strPtr[i] != NULL; i++)
{
aux = strtok (NULL, str2);
strcpy (strPtr[i], aux);
}
for (i = 0; i < 10; i++)
{
puts(strPtr[i]);
}
return 0;
}
I would say even more: independent of the behaviour of the functions
strcpyandstrtok, that loop in the uninitialized variable is destined to always impact on that error, because almost always the memory region will contain garbage and will never reach thisstrPtr[i] == NULL, therefore every operation made onstrPtr[i]is subject to this problem– Jefferson Quesado
Thank you, it worked now! You could explain to me why when I declare
char *auxoutside theforshe gives this Warning "assignment makes integer from Pointer without a cast" ?– Thiago Rizzi
@Weird Thiagorizzi, I moved the statement out of the
forand compiled without problems. Are sure that this was your only change?– mercador
@Strange merchant that I went to test and worked now, strange things happen in kkkk programming
– Thiago Rizzi