コード例 #1
0
ファイル: util.c プロジェクト: pilliq/lumberjacks
/****** CLEANING LINKED LIST *********/ 
void destoryNode(commandNode node)
{
	if (node != NULL)
	{
		cleanArray(node->command, node->size);
	}
}
コード例 #2
0
ファイル: server.c プロジェクト: Ramese/servoPi
int main() {
	int server_sockfd, client_sockfd;
	int server_len, client_len;
	struct sockaddr_in server_address;
	struct sockaddr_in client_address;
	char ch[10];
	int otackyZaMin;
	int64_t pozadovanaRychlost;
	FILE *fd;
	char * myfifo = "/media/ramdisk/otackyFIFO";
	puts("Inicializuju FIFO");
	mkfifo(myfifo, 0666);	
	
	puts("Vyplnuji pole");
	inicializacePole();
	
	/* odstraníme všechny staré sockety a vytvoříme nový nepojmenovaný socket  */
	unlink("server_socket");
	server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
	
	/* pojmenovani socketu */
	server_address.sin_family = AF_INET;
	server_address.sin_addr.s_addr = htonl(INADDR_ANY);
	server_address.sin_port = htons(9050);
	server_len = sizeof(server_address);
	bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
	
	/* fronta pro pripojeni a cekani na klienty */
	listen(server_sockfd, 5);
	while(1) {
	/* prijmuti pripojeni */
		client_len = sizeof(client_address);
		client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, (socklen_t *)&client_len);
	/* cteme a piseme klientovi na client_sockfd */
		cleanArray(ch, 10);
		if(read(client_sockfd, ch, 10) == -1){
			puts("navratova hodnota je -1");
		}
		close(client_sockfd);
		/*printf("pozice kurzoru %d\n", (int)lseek(client_sockfd, 0, SEEK_CUR));*/
		/*ch[0]++;
		write(client_sockfd, &ch, 1);*/
		sscanf(ch, "%d", &otackyZaMin);
/*		printf("Otacky za min: %d\n", otackyZaMin);*/
		pozadovanaRychlost = getRequestedSpeed((double)otackyZaMin/150.0);
/*		printf("Pozadovana rychlost: 0x%08x%08x\n", (unsigned int)(pozadovanaRychlost>>32), (unsigned int)pozadovanaRychlost);*/
/*		puts("pokousim se o zapis");*/
/*		puts("Oteviram FIFO");*/
		fd = fopen(myfifo, "w");
		if(fwrite(&pozadovanaRychlost,sizeof(int64_t),1,fd) != 1){
			puts("Chyba pri zapisu");
		}
/*		puts("konec zapisu");*/
		fclose(fd);
		
	}
	
	unlink(myfifo);
} /* main */
コード例 #3
0
ファイル: util.c プロジェクト: pilliq/lumberjacks
void cleanCommands(Commands c)
{
	printf("You're supposed to clean me\n");
	
	commandNode n, prev;
	
	if (c->head == NULL)
	{
		return;
	}
	
	n = c->head->next;
	prev = c->head;
	if (n == NULL) 
	{	
		cleanArray(prev->command, prev->size);
		free(prev);
	}
	else
	{	
		cleanArray(prev->command, prev->size);
		free(prev);
		prev = NULL;
		
		while (n != NULL)
		{
			cleanArray(n->command, n->size);
			free(prev);
			prev = n;
			n = n->next;
		}
		free(prev);
	}
	c->size = 0;
	free(c); 
}
コード例 #4
0
ファイル: main.c プロジェクト: William-Hai/OpenJudge
int main()
{
	int i, j, k, a[10]={0}, n, h;
	while(scanf("%d",&n)!=EOF)
	{
		// 结束
		if(n == 0)
		{
			break;
		}
		
		// 赋值数组
		for(i = 1; i <= n; i++)
		{
			a[i]=i;
		}
		printArray(a);
		
		for(;;){
			j=0;
			for(i=1;i<n;i++)
			{
				if(a[i]<a[i+1])
				{
					j++;
				}
			}
			if(j==0)
			{
				break;
			}
			for(i=n-1;i>0;i--)
			{
				if(a[i]<a[i+1])
				{
					break;
				}
			}
			j=a[i+1];
			for(h=i+1;h<=n;h++)
			{
				if(a[h]<=j&&a[h]>a[i])
				{
					j=a[h];
					k=h;
				}
			}
			h=a[i];a[i]=a[k];a[k]=h;
			int b[10]={0};j=0;k=i+1;
			for(;k<=n;k++)
			{
				b[j]=a[k];j++;
			}
			k=i+1;j--;
			for(;k<=n;k++)
			{
				a[k]=b[j];j--;
			}
			printArray(a);
		}
		cleanArray(a);
	}
	return 0;
}