added weekly exercises of isp-ws25

This commit is contained in:
2026-04-13 19:02:19 +02:00
parent c51e836ed9
commit 00fdd31a18
28 changed files with 1835 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
/*
In this task, you should find mistakes in the given source code.
The idea is to represent multiple characters as words stored as linked lists.
The code creates five elements of the struct Character.
Each element has a member content_ (the actual character) and
a pointer to the next character in the word (next_).
The printAll-function should correctly print all the elements inside the linked list.
Unfortunately, there are some errors in the code.
The compiler finds a few of them, others are logical errors and are not detected by the compiler.
Zum Beispiel:
Resultat
hello
*/
//#include "stdio.h"
#include <stdio.h> // General libraries should always be included with <>
// including with "" searches in compile directory first
typedef struct _Character_
{
char content_;
//Character* next_;
struct _Character_ *next_;
} Character;
void printAll(Character* head)
{
//if (head = NULL)
if (head == NULL)
return;
Character* it = head;
while (it != NULL)
{
printf("%c", it->content_);
it = it->next_;
}
}
/*
If you want a recursive printAll call:
void printAll(Character *head)
{
if (head == NULL) return; // guard against empty list
putchar(head->content_); // if here, prints first -> last
printAll(head->next_);
putchar(head->content_); // if here, prints last -> first
}
*/
int main(void)
{
Character e = {'o', NULL};
Character d = {'l', &e};
Character c = {'l', &d};
Character b = {'e', &c};
Character a = {'h', &b};
printAll(&a);
}