Skip to content
Sign upLog in
← Back to Community
Interpreter
Profile icon
Arabica

One thing is that I am having buffer overflow for no reason at all. Even "%c" overflows.

Voters
Profile icon
BrandonKam2
Profile icon
Arabica
Comments
hotnewtop
Profile icon
Klokat

I've changed your code a bit. First and foremost char input[] = "" won't allocate any space I think. I think I fixed the while loop as well. I don't know where you wanna go with this after. But good luck! Also check your twitch chat for help next time! :D

#include <stdio.h> /* For printf() */ #include <string.h> /* For tokenizing and comparing */ #include <stdlib.h> /* For getline() */ int main() { char input[256]; fflush(stdin); scanf("%[^\n]s", input); /* const char *delim = " "; const char *delim1 = "("; const char *delim2 = ")"; const char *delim3 = "\""; const char *delim4 = "\'"; const char *delim5 = "\n"; */ char *token = strtok(input, " "); while(token != NULL) { printf("Token: %s\n", token); if(strncmp(token, "print", 5) == 0) { printf("%s\n", token); } token = strtok(NULL, " "); } }

As a side note fgets is probably a better way to go instead of scanf in this case.