1
#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

Sean Ervinson
  • 103
  • 5
  • 12

1 Answers1

3

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)
melpomene
  • 81,915
  • 7
  • 76
  • 137