i would like to ask something again about why i am not getting my elements displayed by trying it to put out through a linked list.
I was following one tutorial for this matter but although it seems to me that i done everything as shown in a video it still doesn't work.
So I am trying to display my data from the array feld[N] through my structure student_t. I know that for a linked list i need multiple nodes but i wanted just to print out the first one and see if it works.
My code looks like that at the momment:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define MAX_NAME_LEN 50
#define N 20
struct student {
unsigned int nummer;
char name[MAX_NAME_LEN];
};
typedef struct student student_t;
int element_vergleich(const void* p1, const void* p2)
{
student_t* sp1, * sp2;
sp1 = (student_t*)p1;
sp2 = (student_t*)p2;
if (sp1->nummer < sp2->nummer)
return -1;
else if (sp1->nummer > sp2->nummer)
return 1;
else
return 0;
}
void sortiere(student_t* f, int n)
{
qsort(f, n, sizeof(student_t), element_vergleich);
}
struct listelem
{
struct student;
struct listelem *link;
};
int main(void)
{
student_t feld[N] = { {59112, "Peter Lustig"}, {45181, "Fritz Fuchs"}, {38984, "Bibi Blocksberg"},
{87191, "Bernd Brot"}, {58731, "Katie Sommer"}, {75442, "Hein Klug"} };
int n = 7; // Anzahl benutzter Elemente im Feld
strcpy(feld[6].name, "Linas Dagys");
feld[6].nummer = 50846;
printf("Das Feld wurde fuer %d Elemente deklariert. Davon werden %d Elemente benutzt.\n", N, n);
struct listelem* anker = NULL;
anker = (struct listelem*)malloc(sizeof(struct listelem));
anker->nummer;
anker->name;
anker->link = NULL;
printf(" Nummer: %d, Name: %s", anker->nummer, anker->name);
return 0;
}