#my C code crashes and IDK why

8 messages · Page 1 of 1 (latest)

steep pond
#

my C code is supposed to 3 inputs, 2 ints and a string, but after inputing the string it crashes

#

#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

final forge
#

U still need help?

lusty raven
#

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