I am new in C and tried checking the loop condition as to find on the internet, but I get this error I am not able to solve (no other questions/answers were helpful):
void main() {
char* insert = malloc(30);
printf("Insert a Molecular Formula:\n");
gets(insert);
if (insert) {
for (int i = 0; insert[i] != '\0'; i++) {
}
} }
I get the error 6011 in VS inside the for-loop when checking insert[i] != '\0'
.
I haven't found a good fix, I have tried cheking return of malloc like if(!insert){ //above code here}
but this didn't help.
Thanks in advance.