示例#1
0
int main(void){
  char command, buf[40];

  head.next = NULL;

  do{
    printf("comm? a:add p:print q:quit\n");
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%c", &command);

    switch(command){
    case 'a':
      addlist();
      showlist();
      break;
    case 'p':
      showlist();
      break;
    case 'q':
      break;
    default:
      printf("error\n");
      break;
    }
  }while(command != 'q');

  return 0;
}
void main()
{
    printf("#############  Welcome to Linked List Operations ########## \n \n");
    list *head1=NULL,*head2=NULL;
    head1=create(head1);
    head2=create(head2);
    showlist(head1);
    showlist(head2);
    printf("\nThe merged linked list is created....\n");
    showlist(mergedlist(head1,head2));
}
示例#3
0
int main(void)
{
   ListPtr list1 = createlist('0');
   ListPtr list2 = createlist('A');

   showlist(list1);
   showlist(list2);

   concatenate(list1, list2);

   showlist(list1);

   return 0;
} /* E0F main */
示例#4
0
文件: listcalc.c 项目: clamiax/misc
int main(void)
{
   List *mylist = NULL;
   int i, sum = 0;
   double media = 0;

   srand( time(NULL) );

   for(i = 0; i < 25; i++)
      insert(&mylist, 1 + rand() % 100);

   showlist(mylist);

   /* calculate the sum */
   while( mylist != NULL ) {
      sum += mylist->n;
      ++media;

      mylist = mylist->next;
   }

   media = sum / media;

   printf("Sum: %d\nMedia: %.2f\n", sum, media);

   return 0;
} /* E0F main */
示例#5
0
int main(void)
{
    element list[SIZE] = {{5},{3},{2},{6},{1}};
    puts("befor sorting:");
    showlist(list, SIZE);

    puts("sort ascendingly:");
    insertion_sort(list, SIZE, ascending);
    showlist(list, SIZE);

    puts("sort descendingly:");
    insertion_sort(list, SIZE, descending);
    showlist(list, SIZE);
    return 0;
    return 0;
}
示例#6
0
int main(int argc, char** argv) {
    list l1 = emptylist();
    int el;
    do {
        printf("\n Introdurre valore:\t");
        el=getElement();
        l1 = insord2(el, l1);
    } while (el!=0); /* condiz. arbitraria */
    showlist(l1);
    getchar();
    return 0;
}
示例#7
0
int main(int argc, char *argv[])
{
	int a[10]={
		1,3,5,4,2,6,8,9,10,13
	};
	int i;
	list_t list=creatlist();
	for(i=0;i<10 ; i++)
	{
		insernext(list,list.last,a[i]);
	}
	showlist(list);
	
	return 0;
}
void main()
{
    printf("#############  Welcome to Linked List Operations ########## \n \n");
    printf("Creating a linked list.......\n");
    int n=0;
    list *head=NULL;
     head=create(head);
     showlist(head);
     printf("\nEnter the nth node from the last you want to see=");
     scanf("%d",&n);
     if(findnthnode(head,n)!=NULL)
       printf("The %dth node from the last is = %d",n,findnthnode(head,n)->data);
     else
        printf("Node doesnot exist !!!");

}
示例#9
0
int main( int argc, char** argv )
{
    printf( "evas list test\n" );

    integerList list;
    showlist( list );

    int* theAnswer = new int( 42 );

    list.append( new int( 10 ) );
    list.append( new int( 10 ) );
    list.append( new int( 10 ) );
    showlist(list);
    list.append( new int( 10 ) );
    list.append( theAnswer );
    list.prepend( new int( 20 ) );
    list.append( new int( 10 ) );
    list.append( new int( 10 ) );
    showlist( list );
    list.append( new int( 20 ) );
    showlist( list );
    list.append( new int( 30 ) );
    showlist( list );
    list.prepend( new int( -10 ) );
    showlist( list );

    printf( "listfind false = %p\n", list.find( new int( 10 ) ) );
    printf( "listfind true = %p\n", list.find( theAnswer ) );

    for ( integerListIterator it( list ); *it; ++it )
    {
        printf( "data is now %d\n", **it );
    }

    integerListIterator fourtyTwo = list.iter( theAnswer );
    printf( "fourtyTwo = %d\n", **fourtyTwo );
    ++fourtyTwo;
    printf( "value after fourtyTwo = %d\n", **fourtyTwo );

    return 0;
}
示例#10
0
/*
 * Main command processor.
 * Accept and execute commands until a quit command, then return.
 */
void
commands(void)
{
	int c, action;

	last_mca = 0;
	nscroll = (sc_height + 1) / 2;

	for (;;) {
		mca = 0;
		number = 0;

		/*
		 * See if any signals need processing.
		 */
		if (sigs) {
			psignals();
			if (quitting)
				quit();
		}
		/*
		 * Display prompt and accept a character.
		 */
		CMD_RESET;
		if (!prompt()) {
			next_file(1);
			continue;
		}
		noprefix();
		c = getcc();

again:		if (sigs)
			continue;

		/*
		 * If we are in a multicharacter command, call mca_char.
		 * Otherwise we call cmd_decode to determine the
		 * action to be performed.
		 */
		if (mca)
			switch (mca_char(c)) {
			case MCA_MORE:
				/*
				 * Need another character.
				 */
				c = getcc();
				goto again;
			case MCA_DONE:
				/*
				 * Command has been handled by mca_char.
				 * Start clean with a prompt.
				 */
				continue;
			case NO_MCA:
				/*
				 * Not a multi-char command
				 * (at least, not anymore).
				 */
				break;
			}

		/* decode the command character and decide what to do. */
		switch (action = cmd_decode(c)) {
		case A_DIGIT:		/* first digit of a number */
			start_mca(A_DIGIT, ":");
			goto again;
		case A_F_SCREEN:	/* forward one screen */
			CMD_EXEC;
			if (number <= 0 && (number = sc_window) <= 0)
				number = sc_height - 1;
			forward(number, 1);
			break;
		case A_B_SCREEN:	/* backward one screen */
			CMD_EXEC;
			if (number <= 0 && (number = sc_window) <= 0)
				number = sc_height - 1;
			backward(number, 1);
			break;
		case A_F_LINE:		/* forward N (default 1) line */
			CMD_EXEC;
			forward(number <= 0 ? 1 : number, 0);
			break;
		case A_B_LINE:		/* backward N (default 1) line */
			CMD_EXEC;
			backward(number <= 0 ? 1 : number, 0);
			break;
		case A_F_SCROLL:	/* forward N lines */
			CMD_EXEC;
			if (number > 0)
				nscroll = number;
			forward(nscroll, 0);
			break;
		case A_B_SCROLL:	/* backward N lines */
			CMD_EXEC;
			if (number > 0)
				nscroll = number;
			backward(nscroll, 0);
			break;
		case A_FREPAINT:	/* flush buffers and repaint */
			if (!ispipe) {
				ch_init(0, 0);
				clr_linenum();
			}
			/* FALLTHROUGH */
		case A_REPAINT:		/* repaint the screen */
			CMD_EXEC;
			repaint();
			break;
		case A_GOLINE:		/* go to line N, default 1 */
			CMD_EXEC;
			if (number <= 0)
				number = 1;
			jump_back(number);
			break;
		case A_PERCENT:		/* go to percent of file */
			CMD_EXEC;
			if (number < 0)
				number = 0;
			else if (number > 100)
				number = 100;
			jump_percent(number);
			break;
		case A_GOEND:		/* go to line N, default end */
			CMD_EXEC;
			if (number <= 0)
				jump_forw();
			else
				jump_back(number);
			break;
		case A_STAT:		/* print file name, etc. */
			longprompt = 1;
			continue;
		case A_QUIT:		/* exit */
			quit();
		case A_F_SEARCH:	/* search for a pattern */
		case A_B_SEARCH:
			if (number <= 0)
				number = 1;
			start_mca(action, (action==A_F_SEARCH) ? "/" : "?");
			last_mca = mca;
			wsearch = 1;
			c = getcc();
			if (c == '!') {
				/*
				 * Invert the sense of the search; set wsearch
				 * to 0 and get a new character for the start
				 * of the pattern.
				 */
				start_mca(action, 
				    (action == A_F_SEARCH) ? "!/" : "!?");
				wsearch = 0;
				c = getcc();
			}
			goto again;
		case A_AGAIN_SEARCH:		/* repeat previous search */
			if (number <= 0)
				number = 1;
			if (wsearch)
				start_mca(last_mca, 
				    (last_mca == A_F_SEARCH) ? "/" : "?");
			else
				start_mca(last_mca, 
				    (last_mca == A_F_SEARCH) ? "!/" : "!?");
			CMD_EXEC;
			(void)search(mca == A_F_SEARCH, (char *)NULL,
			    number, wsearch);
			break;
		case A_HELP:			/* help */
			lower_left();
			clear_eol();
			fputs("help", stdout);
			CMD_EXEC;
			help();
			break;
		case A_TAGFILE:			/* tag a new file */
			CMD_RESET;
			start_mca(A_TAGFILE, "Tag: ");
			c = getcc();
			goto again;
		case A_FILE_LIST:		/* show list of file names */
			CMD_EXEC;
			showlist();
			repaint();
			break;
		case A_EXAMINE:			/* edit a new file */
			CMD_RESET;
			start_mca(A_EXAMINE, "Examine: ");
			c = getcc();
			goto again;
		case A_VISUAL:			/* invoke the editor */
			if (ispipe) {
				error("Cannot edit standard input");
				break;
			}
			CMD_EXEC;
			editfile();
			ch_init(0, 0);
			clr_linenum();
			break;
		case A_NEXT_FILE:		/* examine next file */
			if (number <= 0)
				number = 1;
			next_file(number);
			break;
		case A_PREV_FILE:		/* examine previous file */
			if (number <= 0)
				number = 1;
			prev_file(number);
			break;
		case A_SETMARK:			/* set a mark */
			lower_left();
			clear_eol();
			start_mca(A_SETMARK, "mark: ");
			c = getcc();
			if (c == erase_char || c == kill_char)
				break;
			setmark(c);
			break;
		case A_GOMARK:			/* go to mark */
			lower_left();
			clear_eol();
			start_mca(A_GOMARK, "goto mark: ");
			c = getcc();
			if (c == erase_char || c == kill_char)
				break;
			gomark(c);
			break;
		case A_PREFIX:
			/*
			 * The command is incomplete (more chars are needed).
			 * Display the current char so the user knows what's
			 * going on and get another character.
			 */
			if (mca != A_PREFIX)
				start_mca(A_PREFIX, "");
			if (CONTROL_CHAR(c)) {
				putchar('^');
				c = CARAT_CHAR(c);
			}
			putchar(c);
			c = getcc();
			goto again;
		default:
			putchar('\7');
			break;
		}
	}
}
示例#11
0
void VideoDialog::readydata(QByteArray datagram)
{
    int find;
    int cnt = datagram.count('@');
    printf("cnt : %d\n", cnt);

    id1 = id2 = id3 = id4 = id5 = id6 = NULL;

    if(cnt>=1) id1 = datagram.mid(1, 3);
    if(cnt>=2) id2 = datagram.mid(4, 3);
    if(cnt>=3) id3 = datagram.mid(7, 3);
    if(cnt>=4) id4 = datagram.mid(10, 3);
    if(cnt>=5) id5 = datagram.mid(13, 3);
    if(cnt>=6) id6 = datagram.mid(16, 3);

    if(cnt>=1) time1 = datagram.mid(19, 4).insert(2, ':');
    if(cnt>=2) time2 = datagram.mid(23, 4).insert(2, ':');
    if(cnt>=3) time3 = datagram.mid(27, 4).insert(2, ':');
    if(cnt>=4) time4 = datagram.mid(31, 4).insert(2, ':');
    if(cnt>=5) time5 = datagram.mid(35, 4).insert(2, ':');
    if(cnt>=6) time6 = datagram.mid(39, 4).insert(2, ':');

    datagram = datagram.mid(43);
    if(cnt>=1)
    {
        find = datagram.indexOf('@', 0);
        name1 = datagram.left(find);
        datagram = datagram.mid(find+1);
    }
    if(cnt>=2)
    {
        find = datagram.indexOf('@', 0);
        name2 =  datagram.left(find);
        datagram = datagram.mid(find+1);
    }
    if(cnt>=3)
    {
        find = datagram.indexOf('@', 0);
        name3 =  datagram.left(find);
        datagram = datagram.mid(find+1);
    }
    if(cnt>=4)
    {
        find = datagram.indexOf('@', 0);
        name4 =  datagram.left(find);
        datagram = datagram.mid(find+1);
    }
    if(cnt>=5)
    {
        find = datagram.indexOf('@', 0);
        name5 =  datagram.left(find);
        datagram = datagram.mid(find+1);
    }
    if(cnt>=6)
    {
        find = datagram.indexOf('@', 0);
        name6 =  datagram.left(find);
        datagram = datagram.mid(find+1);
    }

    showlist();
}
示例#12
0
int main (int argc, char const * argv [])

{
	extern struct channel channel;
	static char const * optv [] =
	{
		"ACD:ef:i:l:M:o:qRS:t:vxz:",
		"device [device] [...] [> stdout]",
		"Qualcomm Atheros VLANID Forward Configuration Manager",
		"A\tadd VLAN ID of multiple slaves to memory",
		"C\tcommit configuration to flash memory",
		"D x\tset default VLAN ID",
		"e\tredirect stderr to stdout",
		"f s\tread VLANIDS from file (s)",

#if defined (WINPCAP) || defined (LIBPCAP)

		"i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",

#else

		"i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",

#endif

		"l n\tdata length in bytes [" LITERAL (PLCFWD_LENGTH) "]",
		"M n\tenable VLANID forwarding on the master",
		"o x\tdata offset in bytes [" LITERAL (PLCFWD_OFFSET) "]",
		"q\tquiet mode",
		"R\tremove VLAN ID of multiple slaves from memory",
		"S n\tenable VLANID forwarding on all slaves",
		"t n\ttimeout is (n) millisecond [" LITERAL (CHANNEL_TIMEOUT) "]",
		"v\tverbose mode",
		"x\texit on error",
		"z s\tslavespec",
		(char const *) (0)
	};

#include "../plc/plc.c"

	struct item list [128];
	unsigned size = sizeof (list) / sizeof (struct item);
	unsigned items = 0;
	uint32_t offset = 0;
	uint32_t length = 0;
	signed c;
	memset (&list, 0, sizeof (list));
	if (getenv (PLCDEVICE))
	{
		channel.ifname = strdup (getenv (PLCDEVICE));
	}
	optind = 1;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'A':
			plc.action = PLCFWD_ADD;
			break;
		case 'C':
			plc.action = PLCFWD_STO;
			break;
		case 'D':
			plc.action = PLCFWD_SET;
			list [0].VLANID [0] = (uint16_t)(basespec (optarg, 10, sizeof (uint16_t)));
			break;
		case 'e':
			dup2 (STDOUT_FILENO, STDERR_FILENO);
			break;
		case 'f':
			if (!freopen (optarg, "rb", stdin))
			{
				error (1, errno, "%s", optarg);
			}
			items += readlist (&list [items], size - items);
			break;
		case 'i':

#if defined (WINPCAP) || defined (LIBPCAP)

			channel.ifindex = atoi (optarg);

#else

			channel.ifname = optarg;

#endif

			break;
		case 'M':
			plc.action = PLCFWD_CTL;
			plc.module = (uint8_t)(uintspec (synonym (optarg, states, STATES), 0, UCHAR_MAX));
			break;
		case 'l':
			length = (uint32_t) (basespec (optarg, 10, sizeof (length)));
			break;
		case 'o':
			offset = (uint32_t) (basespec (optarg, 10, sizeof (offset)));
			break;
		case 'q':
			_setbits (channel.flags, CHANNEL_SILENCE);
			_setbits (plc.flags, PLC_SILENCE);
			break;
		case 'R':
			plc.action = PLCFWD_REM;
			break;
		case 'S':
			plc.action = PLCFWD_CTL;
			plc.pushbutton = (uint8_t)(uintspec (synonym (optarg, states, STATES), 0, UCHAR_MAX));
			break;
		case 't':
			channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
			break;
		case 'v':
			_setbits (channel.flags, CHANNEL_VERBOSE);
			_setbits (plc.flags, PLC_VERBOSE);
			break;
		case 'x':
			_setbits (plc.flags, PLC_BAILOUT);
			break;
		case 'z':
			readitem (&list [items++], optarg);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;

#if 0

	showlist (list, items);

#endif

	openchannel (&channel);
	if (!(plc.message = malloc (sizeof (* plc.message))))
	{
		error (1, errno, PLC_NOMEMORY);
	}
	if (!argc)
	{
		function (&plc, offset, length, list, items);
	}
	while ((argc) && (* argv))
	{
		if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
		{
			error (1, errno, PLC_BAD_MAC, * argv);
		}
		function (&plc, offset, length, list, items);
		argv++;
		argc--;
	}
	free (plc.message);
	closechannel (&channel);
	return (0);
}