view test/list/testlist.c @ 0:5b089096921f

first commit.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Dec 2009 21:57:05 +0900
parents
children 803d6bf22e6d
line wrap: on
line source

#include<stdio.h>
#include<string.h>

#include"List.h"

void printList(List *list);

int
main(int argc, char **argv)
{
	char buff[BUFSIZ];
	List *list=NULL;

	while (fgets(buff, BUFSIZ, stdin)!=NULL) {
		int size = strlen(buff);
		char *newstr;

		if (buff[size-1]=='\n') {
			buff[size-1]='\0';
			size--;
		}
		if (strncmp(buff, "d:", 2)==0) {
			int count;
			char *s;
			count = atoi(buff+2);
			s = _listGetnthData(list, count);
			if (s) {
				printf("%s\n", s);
				list = _listRemove(list, s);
			}
		} else {
			newstr = strdup(buff);
			list = _listAddFirst(list, newstr);
		}

		printList(list);
	}

}


int printOne(void *data,void *arg)
{
	char *s = data;
	printf("%s > ", s);
	return 1;
}
void
printList(List *list)
{
	_listApply(list, printOne, NULL);
	printf("\n");
}