
手机里面的格式和电脑的应该不会有区别,建议你能用电脑就尽量用电脑,手机效率实在太低……
下面指出你的三个错误:
main函数后面要加()
printf函数格式是printf("heh");
main()的后面要加{ ,printf("heh");后面要加 }
注意:以上符号均为英文输入状态下的符号。
望采纳
两种方法:
1
JNI。在安卓上层通过JNI调用底层c的程序。
2
把c语言改成JAVA。
你的程序是不能直接放在手机里面运行的,不过你可以把你的c文件放到手机里,用C4droid这个安卓程序运行。
用c++写安卓手机软件的方法:
安装ndk,使用纯c++开发安卓程序,下边是详细的步骤与说明:
1、编写入口函数
android_main为入口函数,和C++中的main函数是一样的。这里创建CELLAndroidApp的对象,直接调用main函数。
void android_main(struct android_app state)
{
CELLAndroidApp app(state);
appmain(0,0);
}
2绘制类的实现说明
protected:
EGLConfig _config;
EGLSurface _surface;
EGLContext _context;
EGLDisplay _display;
android_app _app;
int _width;
int _height;
部分参数说明:
_surface:用于绘制图形,相当于windows绘图中的位图
_context:可以看做是opengl对象
_display:用于绘图的设备上下文,类似于windows绘图中的dc
3构造函数说明
CELLAndroidApp(android_app app):_app(app) { _surface = 0; _context = 0; _display = 0; _width = 64; _height = 48; app->userData = this; //用户数据 app->onAppCmd = handle_cmd; //窗口的创建销毁等 app->onInputEvent = handle_input; //回调函数 }
值得注意的是,这里的app中的userData,传入用户数据,这里直接传入this,onAppCmd传入的handle_cmd回调函数,onInputEvent传入的事handle_input回调函数
4类中函数main()说明
virtual void main(int argc,char argv)
{
int ident;
int events;
android_poll_source source;
while (true)
{
while ((ident = ALooper_pollAll(0, NULL, &events, (void)&source)) >= 0)
{
if (source != NULL)
source->process(_app, source); //有触摸事件,调用input函数,相当于dispatchmessage
if (_app->destroyRequested != 0)
return;
}
render();
}
}
5调用render()函数,绘制图形。
6初始化设备函数initDevice()
virtual void initDevice()
{
const EGLint attribs[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
EGLint format;
EGLint numConfigs;
_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(_display, 0, 0);
eglChooseConfig(_display, attribs, &_config, 1, &numConfigs);
eglGetConfigAttrib(_display, _config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, format);
_surface = eglCreateWindowSurface(_display, _config, _app->window, NULL);
#if 0
EGLint contextAtt[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
_context = eglCreateContext(_display, _config, 0, contextAtt);
#else
_context = eglCreateContext(_display, _config, 0, 0);
#endif
if (eglMakeCurrent(_display, _surface, _surface, _context) == EGL_FALSE)
{
LOGW("Unable to eglMakeCurrent");
return;
}
eglQuerySurface(_display, _surface, EGL_WIDTH, &_width);
eglQuerySurface(_display, _surface, EGL_HEIGHT, &_height);
onCreate();
// Initialize GL state
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
glViewport(0,0,_width,_height);
glOrthof(0,_width,_height,0,-100,100);
7绘制函数render()
virtual void render()
{
if(_display == 0)
{
return;
}
glClearColor(0,0,0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
if(g_arVertexsize() >= 2)
{
glColor4f(1,1,1,1);
glVertexPointer(3,GL_FLOAT,0,&g_arVertex[0]);
glDrawArrays(GL_LINE_STRIP,0,g_arVertexsize());
}
eglSwapBuffers(_display,_surface); //双缓存的交换缓冲区
}
8编译程序,将程序导入到模拟器中,最终运行的效果图如下:
android上现在有两个方向,一个是基于SDK的开发,主要是 用JAVA,另外一个就是NDK的开发,主要语言就是C、C++,C,C++可以再在android中做第三方的开发,人才急缺,主要是将一些功能本地化。
以上就是关于用安卓c语言写程序怎么老是错误,不和电脑上的一样啊,请教一下各位讲讲一些基本的语句、格式啊~~~~全部的内容,包括:用安卓c语言写程序怎么老是错误,不和电脑上的一样啊,请教一下各位讲讲一些基本的语句、格式啊~~~~、自己用C语言编了个程序能放入安卓手机使用么、如何用c++写安卓手机软件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)