示例#1
0
文件: ubreak.c 项目: winlibs/icu4c
int c_main( void ) {
  UBreakIterator *boundary;
  char           cStringToExamine[] = "Aaa bbb ccc. Ddd eee fff.";
  UChar          stringToExamine[sizeof(cStringToExamine)+1]; 
  UErrorCode     status = U_ZERO_ERROR;

  printf("\n\n"
	 "C Boundary Analysis\n"
	 "-------------------\n\n");

  printf("Examining: %s\n", cStringToExamine);
  u_uastrcpy(stringToExamine, cStringToExamine);
        
  /*print each sentence in forward and reverse order*/
  boundary = ubrk_open(UBRK_SENTENCE, "en_us", stringToExamine,
		       -1, &status);
  if (U_FAILURE(status)) {
    printf("ubrk_open error: %s\n", u_errorName(status));
    exit(1);
  }

  printf("\n----- Sentence Boundaries, forward: -----------\n"); 
  printEachForward(boundary, stringToExamine);
  printf("\n----- Sentence Boundaries, backward: ----------\n");
  printEachBackward(boundary, stringToExamine);
  ubrk_close(boundary);
    
  /*print each word in order*/
  boundary = ubrk_open(UBRK_WORD, "en_us", stringToExamine,
		       u_strlen(stringToExamine), &status);
  printf("\n----- Word Boundaries, forward: -----------\n"); 
  printEachForward(boundary, stringToExamine);
  printf("\n----- Word Boundaries, backward: ----------\n");
  printEachBackward(boundary, stringToExamine);
  /*print first element*/
  printf("\n----- first: -------------\n");
  printFirst(boundary, stringToExamine);
  /*print last element*/
  printf("\n----- last: --------------\n");
  printLast(boundary, stringToExamine);
  /*print word at charpos 10 */
  printf("\n----- at pos 10: ---------\n");
  printAt(boundary, 10 , stringToExamine);
    
  ubrk_close(boundary);

  printf("\nEnd of C boundary analysis\n");
  return 0;
}
示例#2
0
int main (void) {
  /* program to coordinate the menu options and calls the requested function */

  struct node * first = NULL;   /* pointer to the first list item */
  char option[strMax];          /* user response to menu selection */

  printf ("Program to Maintain a List of Names\n");

  while (1) {
    /* print menu options */
    printf ("Options available\n");
    printf ("I - Insert a name into the list\n");
    printf ("D - Delete a name from the list\n");
    printf ("C - Count the number of items on the list\n");
    printf ("F - Move an item to the front of the list\n");
    printf ("L - Print the last item on the list (iteratively)\n");
    printf ("M - Print the last item on the list (recursively)\n");
    printf ("P - Print the names on the list (iteratively)\n");
    printf ("S - Print the names on the list (recursively)\n");
    printf ("R - Print the names in reverse order\n");
    printf ("Q - Quit\n");

    /* determine user selection */
    printf ("Enter desired option: ");
    scanf ("%s", option);
    
    switch (option[0])
      { case 'I':
        case 'i': 
          addName(&first);
          break;
        case 'D':
        case 'd': 
          deleteName(&first);
          break;
        case 'C':
        case 'c': 
          countList(first);
          break;
        case 'F':
        case 'f': 
          putFirst(&first);
          break;
        case 'L':
        case 'l': 
          printLast(first);
          break;
        case 'M':
        case 'm': 
          printLastRec(first);
          break;
        case 'P':
        case 'p': 
          print(first);
          break;
        case 'S':
        case 's': 
          printRec(first);
          break;
        case 'R':
        case 'r': 
          printReverse(first);
          break;
        case 'Q':
        case 'q':
          printf ("Program terminated\n");
          return 0;
          break;
        default: printf ("Invalid Option - Try Again!\n");
          continue;
      }
  }
}
示例#3
0
int main (void) {
  /* program to coordinate the menu options and calls the requested 
     function */ 

  struct node * first = NULL;   /* pointer to the first list item */
  char option[strMax];          /* user response to menu selection */

  printf ("Program to Maintain a List of Robot Actions\n");

  while (1) {
    /* print menu options */
    printf ("Options available\n");
    printf ("I - Insert an action into the list\n");
    printf ("D - Delete an action from the list\n");
    printf ("C - Count the number of items in the list\n");
    printf ("F - Move an item to the front of the list\n");
    printf ("L - Print the last item in the list\n");
    printf ("P - Print the actions in the list and the UIDs of the nodes\n");
    printf ("R - Print the actions and UIDs in reverse order\n");
    printf ("E - Execute all the action commands contained in the list\n");
    printf ("Q - Quit\n");

    /* determine user selection */
    printf ("Enter desired option: ");
    scanf ("%s", option);
    
    switch (option[0])
      { case 'I':
      case 'i': 
        addAction(&first);
        break;
      case 'D':
      case 'd': 
        deleteAction(&first);
        break;
      case 'C':
      case 'c': 
        countList(first);
        break;
      case 'F':
      case 'f': 
        putFirst(&first);
        break;
      case 'L':
      case 'l': 
        printLast(first);
        break;
      case 'P':
      case 'p': 
        print(first);
        break;
      case 'R':
      case 'r': 
        printReverse(first);
        break;
      case 'E':
      case 'e':
        executeActions(first);
        break;
      case 'Q':
      case 'q':
        printf ("Program terminated\n");
        return 0;
        break;
      default: printf ("Invalid Option - Try Again!\n");
        continue;
      }
  }
}