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.
CodePudding user response:
Error C6011 is a warning, not an error, so your code will run, but it's not bad to handle these issues if Visual Studio is indicating them.
To get the warning to go away, fix your loop like so:
if (insert)
{
for (int i = 0; insert[i] != '\0'; i ) {
}
}