我被困在如何操作數據結構上。C數據結構如何聲明
我有標題是宣佈類似這樣
struct item{
int i;
char str[88];
};
文件,我有一個ç文件,我想打9結構的物品(我聲明爲全局變量,我已經包含頭文件):
struct item a[9];
但是當我想要把我想要的數據到
foo()
{
...
// let's say I have data int in index and char[] in string
// and I want it to put at item_index
a[item_index].i = index;
a[item_index].str = string;
...
}
但是當過我試着編譯它似乎總是顯示
error: expected an identifiler
您需要使用[strcpy](http://linux.die.net/man/3/strcpy)指定給'str' - 'strcpy(a [item_index] .str,string)' – simonc
'基本上所有事情都做對了。唯一的問題是你不能只給C字符串賦「=」;你需要使用像「strcpy()」這樣的函數。 – paulsm4