Christian Christian - 1 month ago 18
C Question

Error: Declaration of non-variable 'strlen' in 'for' loop initial declaration - C

The title is the exact error my compiler(geany on ubuntu) gives me when I try to compile. The part of code in question is the following:

for(int q=strlen(stringA)-1;q>0;q--)
{
//do stuff
}


I've already set the C99 mode and the initialization of variables in the 'for' header is accepted. Is what I did simply illegal in C?

Answer

I assume you are missing an include. Try:

#include <string.h>