Problemer med pointere
Hvorfor får jeg fejl i mine pointer-for-løkke i linie 45 og 53?-------------------------------------------------------
#include <stdio.h>
typedef struct node *nodeptr; //struct node kendes som nodeptr
struct node{ //Struktur for node
char *name;
int grade;
nodeptr *next;
};
nodeptr nodealloc(grade){
struct node *tmp;
tmp=(struct node *) malloc(sizeof(nodeptr));
if (tmp == NULL){
exit(1);
}
tmp->grade = grade;
tmp->next = NULL;
}
nodeptr *head; //holder først adresse i linkedlist
//head=&head
//Omvendt udskrivning
int count1;//Antal objekter i linkedlist
int count2;//Position i linkedlist
//int location;
//Sortering
/*nodeptr max_address;
int max_position;
nodeptr max_next;
nodeptr tmp_head;
*/
main(){
}
void insert_node(struct node node){
node.next = head; //node peger på hvad head peger på
head = *node.next; //head peger på node
}
void printlist(nodeptr head){
nodeptr *tmp;
for(tmp=head;tmp->&next!=NULL;tmp=tmp->next){
printf("%d",tmp->grade);
}
}
int numobjects(nodeptr head){
nodeptr *tmp;
int count=0;
for(tmp=head;tmp!=NULL;tmp=tmp->next){
count1++;
}
return count;
}
noteptr gotoobject(nodeptr head,int location){
nodeptr *tmp;
int count=0;
for(tmp=head;count<location;count2++){
tmp=tmp->next;
}
return tmp;
}
void printlist_rev(nodeptr head,struct node tmp){
for(location=numobjects(head);location>0;location--){
tmp=mapobject(head,location);
prinf("%d",tmp.grade);
}
}
/*void grade_high(nodeptr head){
//VARS---
int max=0;
//-------
count2=0;
for(tmp=head;tmp!=NULL;tmp->next){
count2++;
if(max<(tmp.grade)){
max=(tmp.grade);
max_address=tmp;
max_position=count2;
max_next=tmp->next;
}
}
}
void patch_list(nodeptr head){//fjerner maxobject fra orig. list.
}
void movetosorted(nodeptr head){
} */
void sort_list(nodeptr head){
int count1=numobjects(head);//antal obj. gemmes i count1.
//VARS---
int max=0;
nodeptr max_adress, max_next;
int max_position;
//-------
int count2=0;
for(count1>0;count1--){
/*grade_high*/
max=0;
for(tmp=head;tmp!=NULL;tmp->next){/*problem med ptr=NULL*/
count2++;
if(max<(tmp->grade)){
max=(tmp->grade);
max_address=tmp;
max_position=count2;
max_next=tmp->next;
}
/*patch_list*/
gotoobject(head,max_position-1)->next=max_next;
/*movetosorted*/
max_address=tmp;
tmp->next=tmp_head;
tmp_head=max_address;
}
}