Enable name removement.
This commit is contained in:
1 parent
1c7c27bb7c
commit
946d075c8e
1 file changed
+33
@@ -6,6 +6,9 @@
|
||||
static char names[MAX_NAMES][MAX_NAME_LEN];
|
||||
static unsigned int numberOfNames = 0;
|
||||
|
||||
static int findNameIdx(const char *name);
|
||||
static void removeNameByIdx(unsigned int idx);
|
||||
|
||||
// Fügt einen Namen hinzu. Im Fehlerfall (Archiv ist voll) soll 0, ansonsten 1 zurückgegeben werden.
|
||||
// Ist der angegebene Name länger als die zulässige Namenslänge, wird der Name abgeschnitten hinzugefügt. Rückgabe ist dann 1.
|
||||
int addName(const char *name)
|
||||
@@ -30,9 +33,39 @@ int addNameSorted(const char *name)
|
||||
// Entfernt den angegebenen Namen. Gibt bei Erfolg 1 zurück, ansonsten 0 (Name konnte nicht gefunden werden).
|
||||
int removeName(const char *name)
|
||||
{
|
||||
int nameIdx = findNameIdx(name);
|
||||
|
||||
if(nameIdx >= 0)
|
||||
{
|
||||
removeNameByIdx(nameIdx);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int findNameIdx(const char *name)
|
||||
{
|
||||
for(int i = 0; i < numberOfNames; i++)
|
||||
{
|
||||
if(strcmp(names[i], name) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void removeNameByIdx(unsigned int idx)
|
||||
{
|
||||
for(unsigned i = idx+1; i < numberOfNames; i++)
|
||||
{
|
||||
strncpy(names[i-1], names[i], MAX_NAME_LEN);
|
||||
names[i-1][MAX_NAME_LEN-1] = '\0';
|
||||
}
|
||||
numberOfNames--;
|
||||
}
|
||||
|
||||
// Sortiert die Namen im Archiv aufsteigend.
|
||||
void sortNames()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user