som*_*one 1 c struct data-structures
I am stuck on the on how to manipulate the data structure.
I have header file that declare like this
struct item{
int i;
char str[88];
};
Run Code Online (Sandbox Code Playgroud)
and I have a C file that I want to make 9 structure items (I declare as global variable and I already include the header file):
struct item a[9];
Run Code Online (Sandbox Code Playgroud)
but when I want to put the data that I want into
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;
...
}
Run Code Online (Sandbox Code Playgroud)
but when ever I tried to compile it seem that it always shows
error: expected an identifiler
Run Code Online (Sandbox Code Playgroud)
a[item_index].str = string;
Run Code Online (Sandbox Code Playgroud)
此行不会按照您期望的方式运行.您需要使用strcpy()才能复制字符串:
strcpy(a[item_index].str, string)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |