#include <stdio.h>
#include <string.h>
const int STRING_SIZE = 40;
typedef char string[STRING_SIZE];
char typeInput(string message);
int main()
{
typeInput("Hi my name is Sean");
}
char typeInput(string message)
{
printf(" %s", message);
}
error: variably modified 'string' at file scope i keep getting this error for some reason. Where did I go wrong?
EDIT: just in case i'm using codeblocks
In C, const
doesn't declare a constant, it declares a read-only variable. The compiler complains because STRING_SIZE
is not a constant.
Workaround:
enum { STRING_SIZE = 40 };
// enum creates constants in C (but only integer ones)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.