#my C code crashes and IDK why
8 messages · Page 1 of 1 (latest)
#include <stdio.h>
#include <string.h>
int parking(){
int numTiendas;
scanf("%d", &numTiendas);
char tiendas[1100];
scanf("%c", &tiendas);
char * token = strtok(tiendas, " ");
// loop through the string to extract all other tokens
while( token != NULL ) {
printf( " %s\n", token ); //printing each token
token = strtok(NULL, " ");
}
return 0;
}
int main(){
int testCase;
scanf("%d", &testCase);
for(int i=0; i<testCase; i++){
int ans = parking();
printf("%d", ans);
}
return 0;
}
also the split doesn't workk
U still need help?
Change your 'scanf("%c", &tiendas);' to this
scanf("%1099s", tiendas);
that's whats breaking it
you're reading too many characters when you just scan everything with %c
so set a limit instead and try it again, you'll see an improvement in performance in your code as well