Skip to content
Snippets Groups Projects
Commit 67a7a687 authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Move down a directory

parent e18856a5
No related branches found
No related tags found
No related merge requests found
lib_utils = library('utils', 'utils.c')
#include <stdio.h>
#include <stdlib.h>
int *
get_ints (int argc,
char **argv,
int n,
const char *prompt)
{
int *ret = malloc (sizeof (int) * n);
if (argc != (n + 1))
{
for (int i = 0; i < n; i++)
{
printf ("%s: ", prompt);
scanf ("%d", &ret[i]);
}
}
else
{
for (int i = 0; i < n; i++)
sscanf (argv[i + 1], "%d", &ret[i]);
}
return ret;
}
#pragma once
int *
get_ints (int argc,
char **argv,
int n,
const char *prompt);
sources = files('slist.c', 'test.c')
executable('slist', sources)
#include "slist.h"
#include <stdlib.h>
#include <string.h>
SList *
slist_prepend (SList *list,
void *data)
{
SList *new = malloc (sizeof (SList));
new->data = data;
new->next = list;
return new;
}
void
slist_free_all (SList *list,
FreeFunc func)
{
for (SList *l = list; l; l = l->next)
func (l);
}
#pragma once
typedef void (*FreeFunc) (void *value);
typedef struct _SList SList;
struct _SList
{
void *data;
SList *next;
};
SList * slist_prepend (SList *list,
void *data);
void slist_free_all (SList *list,
FreeFunc func);
#include "slist.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static SList *
add_data (SList *list)
{
char buffer[128];
printf ("Input the data ");
scanf ("%s", buffer);
char *str = strdup (buffer);
return slist_prepend (list, str);
}
static void
print_data (SList *list)
{
SList *l;
for (l = list; l != NULL; l = l->next)
{
printf ("%s\n", (char *) l->data);
}
}
int
main (void)
{
SList *list = NULL;
while (1)
{
list = add_data (list);
print_data (list);
}
slist_free_all (list, free);
return 0;
}
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment