Code Blocks &c语言约瑟夫问题问题

5068人阅读
建立一个最简单的只有一个get_id() 函数的DLL库
&一、创建C语言动态链接库
1.新建一个动态库的工程
File - New - Project - DLL - Go
新建的工程原来的main.cpp和main.h删除,新建两个文件simple.h, simple.c添加进工程
注意默认是cpp文件,我们做C库,要用C文件
#ifndef SIMPLE_H_INCLUDED
#define SIMPLE_H_INCLUDED
#ifdef BUILD_DLL
&&& #define DLL_EXPORT __declspec(dllexport)
&&& #define DLL_EXPORT __declspec(dllimport)
int DLL_EXPORT get_id(void);
int DLL_EXPORT add(int,int);
#endif // SIMPLE_H_INCLUDED
#include &simple.h&
int DLL_EXPORT get_id(void)
&&& return 10;
int DLL_EXPORT add(int x,int y)
&&& return x+y;
然后编译,成功后在bin\Debug目录下生成3个文件:libsimple.dll.a,&simple.dll,libsimple.dll.def
&二、动态链接库调用
1、隐式调用
1)建立一个test的工程File - New - Project - Console application - Go - 选择 c删除main.h,把库的test.h复制到工程中,现在就有main.c 和test.h
#include &stdio.h&
#include &simple.h&
int main()
&&& printf(&id = %d\n&,& get_id() );
&&& printf(&id = %d\n&,& add(1,2) );
system(&pause&);
&&& return 0;
simple.h跟上面一样
2)把dll库添加到工程中
将刚刚生成的两个文件libsimple.a,&&libsimple.dll复制到test工程的bin\Debug目录下
Project - Build options - 左上角默认是Debug,不选这个,选上面那个test - Linker settings - Add 选择 bin\Debug\libsimple.dll.a - 确定,编译成功即可。
2、显示调用
1)建立一个test1的工程File - New - Project - Console application - Go - 选择 编辑main.h,
#include &stdio.h&
#include &windows.h&
typedef int(*lpGet_id)(void); //定义函数类型
typedef int(*lpAdd)(int,int); //定义函数类型
HINSTANCE hD //DLL句柄
lpGet_id get_
int main()
&&& hDll = LoadLibrary(&simple.dll&); //加载 dll
&&& get_id = (lpGet_id)GetProcAddress(hDll, &get_id&);//通过指针获取函数方法
&&& add = (lpAdd)GetProcAddress(hDll, &add&);//通过指针获取函数方法
&&& printf(&id = %d\n&,& get_id() );//调用函数
&&& printf(&id = %d\n&,& add(1,2) );//调用函数
&&& FreeLibrary(hDll);//释放Dll句柄
&&& system(&pause&);
&&& return 0;
simple.h跟上面一样
2)把dll库添加到工程中
将刚刚生成的两个文件libsimple.dll复制到test工程的bin\Debug目录下
编译成功即可。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:89179次
积分:1230
积分:1230
排名:第15103名
原创:15篇
转载:116篇
(2)(2)(3)(4)(16)(66)(20)(1)(1)(1)(3)(1)(11)(3)来 自:中国
等 级:蜘蛛侠
帖 子:314
专家分:1314
&&得分:20&
要弄图形界面的函数貌似只能在TC中,conio.h本来就不是ANSI C的标准库,不具备可移植性,DEV-C++使用的编译系统是GCC系的,所以要在DEV-C++中使用这些不标准的库,需要另外安装,比如curses库。最好百度下,网上看的更详细
版权所有,并保留所有权利。
Powered by , Processed in 0.020826 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved等 级:职业侠客
帖 子:281
专家分:381
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|97|error: expected ';', ',' or ')' before '=' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|109|error: expected ';', ',' or ')' before '=' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|110|error: expected ';', ',' or ')' before '=' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|111|error: expected ';', ',' or ')' before '=' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|112|error: expected ';', ',' or ')' before '=' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|158|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|169|error: conflicting types for 'outtext'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|168|note: previous declaration of 'outtext' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|171|error: conflicting types for 'outtextxy'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|170|note: previous declaration of 'outtextxy' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|173|error: conflicting types for 'textwidth'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|172|note: previous declaration of 'textwidth' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|175|error: conflicting types for 'textheight'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|174|note: previous declaration of 'textheight' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|177|error: conflicting types for 'drawtext'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|176|note: previous declaration of 'drawtext' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|195|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|195|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|195|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|195|error: conflicting types for 'setfont'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|194|note: previous declaration of 'setfont' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|196|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|196|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|196|error: expected declaration specifiers or '...' before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|196|error: conflicting types for 'setfont'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|194|note: previous declaration of 'setfont' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|197|error: conflicting types for 'setfont'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|194|note: previous declaration of 'setfont' was here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|205|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'IMAGE'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|239|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|240|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|241|error: expected declaration specifiers or '...' before 'IMAGE'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|242|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|243|error: expected ';', ',' or ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|244|error: expected ';', ',' or ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|245|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|246|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|247|error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|248|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|249|error: expected ')' before '*' token|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|269|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'InputBox'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|289|error: expected specifier-qualifier-list before 'bool'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|299|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'MouseHit'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|300|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'GetMouseMsg'|
F:\easyx_test\main.c|4|warning: return type of 'main' is not 'int'|
F:\easyx_test\main.c||In function 'main':|
F:\easyx_test\main.c|6|warning: passing argument 1 of 'initgraph' makes pointer from integer without a cast|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|98|note: expected 'int *' but argument is of type 'int'|
F:\easyx_test\main.c|6|warning: passing argument 2 of 'initgraph' makes pointer from integer without a cast|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|98|note: expected 'int *' but argument is of type 'int'|
F:\easyx_test\main.c|6|error: too few arguments to function 'initgraph'|
F:\easyx_test\main.c|7|error: stray '\241' in program|
F:\easyx_test\main.c|7|error: stray '\241' in program|
F:\easyx_test\main.c|7|error: stray '\241' in program|
F:\easyx_test\main.c|7|error: stray '\241' in program|
F:\easyx_test\main.c|8|error: stray '\241' in program|
F:\easyx_test\main.c|8|error: stray '\241' in program|
F:\easyx_test\main.c|8|error: stray '\241' in program|
F:\easyx_test\main.c|8|error: stray '\241' in program|
F:\easyx_test\main.c|9|error: stray '\241' in program|
F:\easyx_test\main.c|9|error: stray '\241' in program|
F:\easyx_test\main.c|9|error: stray '\241' in program|
F:\easyx_test\main.c|9|error: stray '\241' in program|
||=== Build finished: 49 errors, 3 warnings ===|
o(∩∩)Linux & Python 群:
等 级:职业侠客
帖 子:281
专家分:381
不见大大发言……自己顶一个
o(∩∩)Linux & Python 群:
等 级:小飞侠
帖 子:765
专家分:2103
应该是编码方式出问题了。
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
编译器他不认识你的代码&&
是不是你是输入法不对
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
===========深入&-----------------&浅出============
来 自:魔術の禁書目錄
等 级:小飞侠
帖 子:952
专家分:2929
不支持那就不要用它,用能支持的
永远为正义而奋斗,锄强扶弱的Level 5 超能力者
とある魔術の禁書目錄インデックス__御み坂さか美み琴こと
等 级:贵宾
威 望:25
帖 子:4249
专家分:3890
竟然还有人 误导他人不要用标准的编译器, 真是罪过...
没办法,谁让别人是&权威&, 是&砖家&呢!
[ 本帖最后由 BlueGuy 于
11:01 编辑 ]
其实,我是一个演员
来 自:魔術の禁書目錄
等 级:小飞侠
帖 子:952
专家分:2929
我那句话有这么大的歧义吗?
那我补充吧,请楼主不要使用easyx,使用支持mingw的库
想借机人身攻击者自重
永远为正义而奋斗,锄强扶弱的Level 5 超能力者
とある魔術の禁書目錄インデックス__御み坂さか美み琴こと
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
叫兽辛苦了
天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
等 级:贵宾
威 望:25
帖 子:4249
专家分:3890
再怎么新, 也是20年前的技术...
只有20年前的智慧,才能习惯20年前的技术。
[ 本帖最后由 BlueGuy 于
23:21 编辑 ]
其实,我是一个演员
版权所有,并保留所有权利。
Powered by , Processed in 0.027989 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved请问codeblocks中c语言运行时如何单步调试啊?有人说xp的环境下不能调试,是吗?谢谢
请问codeblocks中c语言运行时如何单步调试啊?有人说xp的环境下不能调试,是吗?谢谢 20
可以的啊,它也自带了gdb的,和vc的基本一样,也是在代码区的左侧设置断点,然后在调试项里有单步运行什么的,在上面的菜单里看一下快捷键就OK了
可是断点为啥设置不了啊,而且菜单里也显示不能用,vc是F9设置断点,codeblocks里F9却是编译运行程序啊,麻烦说的详细些吧。
其他回答 (1)
可以调试.先设置断点,然后用F5启动调试.
相关知识等待您来回答
编程领域专家同一C语言程序在VC和codeblocks上运行结果不同,原因是什么?
程序如下,求一个数的“回文数”,即把1234变为4321。但是输入1234后在VC中输出为4321而在codeblocks中输出为4320。求原因&br&#include&stdio.h&&br&#include&math.h&&br&int main()&br&{&br&
int n,k,i=1,m,sum=0;&br&
scanf(&%d&,&n);
//假设n=1234&br&
k=(int)log10(n);
//k为n的位数减1&br&
sum=sum+(int)(n/pow(10,k));
//防止循环中出现pow(10,0) sum=1&br&
printf(&%d\n%d\n&,k,sum);
//调试&br& while(i&k){
//sum=1+2*10+3*100&br&
m=(int)(n/pow(10,k-i));&br&
sum=sum+(m%10)*pow(10,i);&br&
i=i+1;&br&
printf(&%d\n%d\n&,m,sum); //调试&br& }&br& sum=sum+(int)(n%10)*pow(10,k); //防止循环中出现pow(10,0) sum=sum+4*1000&br&
printf(&%d&,sum);&br&
return 0;&br&}&br&发现一个情况可能与这个现象有关但不知道为什么会出现这种现象,&br&运行程序一时输出为99而运行程序二时输出为100,但程序一、二本质上均为求10的2次方的整值的程序,为什么会出现这种差别?&br&程序一:&br&#include&stdio.h&&br&#include&math.h&&br&int main()&br&{&br& int a,c;&br& scanf(&%d&,&a);&br& c=(int)pow(10,a);&br& printf(&%d&,c);&br& return 0;&br&}&br&程序二:#include&stdio.h&&br&#include&math.h&&br&int main()&br&{&br& printf(&%d&,(int)pow(10,2));&br& return 0;&br&}
程序如下,求一个数的“回文数”,即把1234变为4321。但是输入1234后在VC中输出为4321而在codeblocks中输出为4320。求原因#include&stdio.h&#include&math.h&int main(){
int n,k,i=1,m,sum=0;
scanf("%d",&n);
//假设n=1234
k=(int)log10(n);
//k为n的位数减1
sum=sum+(int)(n/pow(10,k));
//防止循环中出现pow(10,0) sum=1
printf("%d\n%d\n",k,sum);
//调试 while(i&k){
//sum=1+2*10+3*100
m=(int)(n/pow(10,k-i));
sum=sum+(m%10)*pow(10,i);
printf("%d\n%d\n",m,sum); //调试 } sum=sum+(int)(n%10)*pow(10,k); //防止循环中出现pow(10,0) sum=sum+4*1000
printf("%d",sum);
return 0;…
按票数排序
应该原因是你每次都强行把pow的结果转换成int,造成精度损失。
首先,求一个数的倒叙为什么这么麻烦,直接以字符串形式读入,然后倒叙输出不就是了么。看了一会儿后看懂了题主的代码,应该是没有问题的,如果出现最后输出是4320,那问题应该在Line8的这句sum=sum+(int)(n/pow(10,k));也就是(int)(1234/pow(10,3))的结果成了0,但我用gcc运行了一下这个的结果是1,是没问题的(VC的编译器是vcc,CodeBlocks默认的编译器是gcc)。
八成是UB,还有implementation defined

我要回帖

更多关于 c语言约瑟夫问题 的文章

 

随机推荐