[英]error: variably modified 'string' at file scope
#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);
}
錯誤:在文件范圍內可變地修改了“字符串”,由於某種原因,我一直收到此錯誤。 我哪里做錯了?
編輯:以防萬一我正在使用代碼塊
在C語言中, const
不聲明常量,而是聲明一個只讀變量。 編譯器抱怨,因為STRING_SIZE
不是常數。
解決方法:
enum { STRING_SIZE = 40 };
// enum creates constants in C (but only integer ones)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.