| 14 | 1/1 | 返回列表 |
| 查看: 1904 | 回復(fù): 13 | |||
[交流]
【討論】VC++與C語(yǔ)言
|
|||
| 感覺有時(shí)候用VC++來(lái)編譯C語(yǔ)言,總是有些莫名其妙的錯(cuò)誤,各位也遇到過嗎? |
» 搶金幣啦!回帖就可以得到:
+1/90
+1/84
+2/66
+2/36
+1/34
+1/34
+1/16
+1/10
+1/10
+1/8
+1/6
+1/6
+1/6
+1/6
+1/5
+1/5
+1/3
+1/2
+1/2
+1/1
|
比如說(shuō)下面這個(gè)C語(yǔ)言,明明沒有錯(cuò)誤,但是用VC編譯總是會(huì)出現(xiàn)錯(cuò)誤: Compiling... lllk.c c:\documents and settings\administrator\桌面\cc\lllk.c(25) : error C2015: too many characters in constant c:\documents and settings\administrator\桌面\cc\lllk.c(25) : error C2061: syntax error : identifier 'bachelor' c:\documents and settings\administrator\桌面\cc\lllk.c(25) : error C2001: newline in constant c:\documents and settings\administrator\桌面\cc\lllk.c(27) : error C2065: 'sortkey' : undeclared identifier c:\documents and settings\administrator\桌面\cc\lllk.c(27) : warning C4047: 'function' : 'char ** ' differs in levels of indirection from 'int ' c:\documents and settings\administrator\桌面\cc\lllk.c(27) : warning C4024: 'sort' : different types for formal and actual parameter 3 Error executing cl.exe. lllk.obj - 4 error(s), 2 warning(s) 程序?yàn)椋?fieldset> #include #include #include typedef struct { char name[10];char degree[10];}ST; void sort(ST x[],int n,char *key[],int m) { int i,j,k,con1,con2; ST v; for(i=0;i { con1=k;break;} for(k=0;k if(con1>con2||con1==con2&&strcmp(x[j].name,x[j+1].name)>0) {v=x[j];x[j]=x[j+1];x[j+1]=v;} } } void main() { ST s[5]={{"A","master"},{"B","bachelor"},{"C",'doctor"},{"D",'bachelor"},{"E","master"}}; char *sortkey[]={"bachelor","master","doctor"};int i; sort(s,5,sortkey,3); for(i=0;i<5;i++) printf("\n%s %s",s[i].name,s[i].degree); getch(); } |
金蟲 (職業(yè)作家)
金蟲 (著名寫手)
|
看到LZ的代碼就想起來(lái)曾經(jīng)也出過這樣的事情: 首先是一個(gè)typedef struct{int a} Foo1; typedef struct {int b} Foo2; 然后我就直接把這個(gè)Foo1和Foo2當(dāng)做類類型在另外一個(gè)類型里面用了: struct Foo2{ Foo1 f1; Foo2 f2; }; 后來(lái)編譯的時(shí)候,直接報(bào)錯(cuò),檢查了好久才發(fā)現(xiàn)這里,F(xiàn)oo1和Foo2是匿名類型,C++里面非常受限制,建議要么直接用.c文件編譯C,要么就用.cpp文件以C++的方式編譯C++代碼,不要依賴什么兼容不兼容,要兼容C用extern "C"{}將C部分聲明出來(lái),風(fēng)格混亂的話出了bug都不知道問題在哪。 |
木蟲 (著名寫手)
| 14 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 070300化學(xué)279求調(diào)劑 +9 | 哈哈哈^_^ 2026-03-31 | 11/550 |
|
|---|---|---|---|---|
|
[考研] 086000生物與醫(yī)藥298調(diào)劑求助 +3 | 元元青青 2026-03-31 | 5/250 |
|
|
[考研] 311求調(diào)劑一志愿合肥工業(yè)大學(xué) +11 | 秋二十二 2026-03-30 | 11/550 |
|
|
[考研] 考研生物與醫(yī)藥調(diào)劑 +6 | 鐵憨憨123425 2026-03-31 | 6/300 |
|
|
[考研] 085601英二數(shù)二求調(diào)劑 總分325 +4 | 余航航 2026-03-31 | 4/200 |
|
|
[考研] 生物學(xué)296求調(diào)劑 +8 | 湯圓包 2026-03-29 | 12/600 |
|
|
[考研] 江蘇蘇北高校誠(chéng)邀調(diào)劑同學(xué) +3 | zzll406 2026-03-31 | 3/150 |
|
|
[考研] 085600 材料與化工 329分求調(diào)劑 +20 | Mr. Z 2026-03-25 | 21/1050 |
|
|
[考研] 317求調(diào)劑 +12 | 蛋黃咸肉粽 2026-03-26 | 13/650 |
|
|
[考研] 289求調(diào)劑 +3 | Acesczlo 2026-03-29 | 4/200 |
|
|
[考研] 270求調(diào)劑 +3 | 小杰pp 2026-03-31 | 4/200 |
|
|
[考研] 276求調(diào)劑 +3 | 趙久華 2026-03-29 | 3/150 |
|
|
[考研] 085601一志愿中山大學(xué)深圳材料工程330求調(diào)劑 +5 | pipiver 2026-03-30 | 5/250 |
|
|
[考研] 279求調(diào)劑 +12 | j的立方 2026-03-29 | 12/600 |
|
|
[考研] 322求調(diào)劑 +10 | 宋明欣 2026-03-27 | 10/500 |
|
|
[考研] 0703本科鄭州大學(xué)求調(diào)劑 +7 | nhj_ 2026-03-25 | 7/350 |
|
|
[考研] 085600,材料與化工321分求調(diào)劑 +10 | 大饞小子 2026-03-28 | 10/500 |
|
|
[考研] 299求調(diào)劑 +10 | 15188958825 2026-03-25 | 10/500 |
|
|
[考研] 332求92調(diào)劑 +8 | 蕉蕉123 2026-03-28 | 8/400 |
|
|
[考研] 本科雙非材料,跨考一志愿華電085801電氣,283求調(diào)劑,任何專業(yè)都可以 +6 | 芝士雪baoo 2026-03-28 | 8/400 |
|