有誰知道爲什麼下面的代碼不適用於char
?它的工作原理與int
秒,但我想用char
初始化結構失敗,並給出類似的警告:使用char來初始化結構的函數 - 解釋我的警告?
warning: assignment makes integer from pointer without a cast
我不知道這是什麼警告裝置。
#include <stdio.h>
#include <stdlib.h>
struct complex {
int re;
int im;
char name;
};
struct complex initialize (int k, int l, char nazwa)
{
struct complex x;
x.re = k;
x.im = l;
x.name= nazwa;
return x;
}
int main()
{
struct complex e;
struct complex f;
int a;
int b;
char o;
int c;
int d;
char p;
a=5;
b=6;
o="t";
e = initialize (a, b, o);
c=8;
d=3;
p="u";
f=initialize (c, d, p);
printf("c1 = (%d,%d)\nc2 = (%d,%d)\n name 1=%s name 2=%s\n", e.re , e.im, f.re, f.im, e.name, f.name);
return 0;
}
你不能說'o =「t」'你需要說'o ='t''。你的問題似乎與一個結構甚至一個函數無關。 –
使用「rb」/「wb」標誌和「char」而不是「const char *」。但這是一個新問題。 – Elazar