为什么我在insertNode()
:
warning: assignment from incompatible pointer type [enabled by default]|
在这一行:
head->next = newNode; //point head's next to the newNode
和
warning: initialization from incompatible pointer type [enabled by default]|
在这一行:
Node *current = head->next;
在我的main()
函数中,我也有这个警告:
warning: passing argument 1 of 'insertNode' from incompatible pointer type [enabled by default]|
在这一行:
insertNode(&head, num);
我的代码中有一些类似于这些警告的其他人。我该如何解决这些问题?
typedef struct NodeStruct{
int data;
struct Node *next;
}Node;
void insertNode(Node *head, int data){
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
if(head->next == NULL){
head->next = newNode;
newNode->next = NULL;
}
else{
Node *current = head->next;
while(current != NULL && current->data < data){
current = current->next;
}
newNode->next = current->next;
current->next = newNode;
}
}
int main(int argc, char *argv[])
{
Node *head = malloc(sizeof(NodeStruct));
head->next = null;
insert(head, 22);
insert(head, 55);
insert(head, 44);
insert(head, 2);
insert(head, 2112);
insert(head, 3);
printList(head);
return 0;
}
答案 0 :(得分:1)
在 public class JNITest {
static{
// System.load("/home/user1/
// JNI_project/mynativelib.so");
System.load("JNITest");
}
// public native void LOSSGREENAMPT(TIMEINTERVAL, STARTINITIALLOSS,double ENDINITIALLOSS,double MOISTUREDEFICIT, double SUCTION,double CONDUCTIVITY, double STARTINFILTRATION,double FINALINFILTRATION, double IMPERVIOUSAREARATIO,int NUMBERPRECIP, double PRECIP(1),double EXCESS(1),int ERRORCODE[4], char ERRORMESSAGE[60],char L_errorMessage[60]);
public static void main(String[] args) {
JNITest test=new JNITest();
//test.greet();
}
}
-
main
预计insertNode(&head, num);
^ don't pass address
,您应该这样称呼它 -
Node *
其他警告是由于上述错误,因为您传递insertNode(head, num);
的地址而不是将head
传递给函数。
同样在head
更改此内容 -
struct NodeStruct
到 -
struct Node *next; // you cannot reference Node in struct itself