jni中log可以代替printf来打印

#include <jni.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include "logs.h"


char *fa() {
    //char *pa = "123456"; // pa 指针在栈区,“123456”在常量区,该函数调用完后指针变量 pa 就被释放了

    char *p = NULL;
    //指针变量 p 在栈中分配 4 字节
    p = (char *) malloc(100);
    //本函数在这里开辟了一块堆区的内存空间,并把地址赋值给 p
    strcpy(p, "wudunxiong 1234566");

    //把常量区的字符串拷贝到堆区
    return p;
    //返回给主调函数 fb(),相对 fa 来说 fb 是主调函数,相对 main 来说,
    //fa(),fb()都是被调用函数
}

char *fb() {
    char *pstr = NULL;
    pstr = fa();
    return pstr;
    //指针变量 pstr 在这就结束
}

void selectSort(int *p, int n) {
    // LOGE("%d\n", p[0]);
    int tmp;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i] > p[j]) {
                tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
            }
        }
    }
}


char *getMem(char **p, int n) {
    *p = (char *) (malloc(n));

    if (*p == NULL) return NULL;
    return *p;
}


void displayArray(int(*p)[4], int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            //printf("%d ", *(*(p + i) + j));
            LOGE("%d ", *(*(p + i) + j));
        }
        putchar(10);
    }
}

int main_s() {
    LOGE("sizeof(char*) = %d\n", sizeof(char *));
    LOGE("sizeof(shor*) = %d\n", sizeof(short *));
    LOGE("sizeof(int*) = %d\n", sizeof(int *));
    LOGE("sizeof(long long*) = %d\n", sizeof(long long *));
    LOGE("sizeof(double *) = %d\n", sizeof(double *));
    LOGE("sizeof(int (*p)[5]) = %d\n", sizeof(int (*)[5]));

    return 0;
}


extern "C" JNIEXPORT jstring JNICALL
Java_com_massky_chars_1s_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    main_s();
    return env->NewStringUTF(hello.c_str());
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值