Example #1
0
void printCount(BstNode* root, char c){
	if (root == NULL)
		printf("\nKhong co");
	else if(root->c == c){
		printf("\nCount of %c : %d", root->c, root->count);
	}
	else if(c < root->c)
		printCount(root->left, c);
	else
		printCount(root->right, c);

}
int count(int alpha[], int stats[])
{
   char c, filename[20];
   FILE *fp;

   printf("What file would you like to read? ");
   scanf("%s", filename);

   fp = fopen(filename, "r");
   if (!fp){
      printf("There was an error finding file %s\n", filename);
      return 1;
   }

   while (1)
   {
      fscanf(fp, "%c", &c);
      if (feof(fp))
         break;
     
      if (isalpha(c)){
         alpha[tolower(c) - 'a']++;
         stats[0]++;
      }
      else if (isspace(c))
         stats[2]++;

      stats[1]++;
   }
   printCount(alpha);
   statistics(stats);
}
Example #3
0
int main(){ 
  
    FILE* img=NULL;
    char target[100];
    char path[100]="\0";
    char* ptr;
    int command;

    if((img = fopen("abc.img","rb"))==NULL) {  
    	myprint("File cannot be opened\n");  
   	    exit(0);  
    } 
     
	struct DirEntry entryListPtr[224];
	
	getBootDirEntry(img,entryListPtr);

//	printBootDir(img,entryListPtr);

	
	
	printAllDir(img,entryListPtr,BPB_RootEntCnt,path);
	
	
	while(1){
		//scanf("%s",target);
		gets(target);
		ptr=target;
		command=commandCheck(ptr);
		
		if(command==1){
			printDetailData(img,entryListPtr,BPB_RootEntCnt,path,ptr);	
		}else if(command==2){
			printCount(img,entryListPtr,BPB_RootEntCnt,path,ptr,""); 
		}else if(command!=-1){
			break;
		}
		
	}
	
//	printDetailData(img,entryListPtr,BPB_RootEntCnt,path,target);
	 
	
//	puts(buffer);

    if(fclose(img)!=0) {  
    	myprint("File cannot be closed\n");   
    	exit(1);   
    }else{
		myprint("File is now closed\n"); 
    }
  
    getchar();
	getchar();
    return 0;
} 
Example #4
0
static void printList(void)
{
	int i, nNum;

	printLine();
	nNum = g_MountProg.GetMountNumber();
	for (i = 0; i < nNum; i++)
		printf("%s\n", g_MountProg.GetClientAddr(i));
	printCount();
	printLine();
}
Example #5
0
//exeute history command
void execHistory(char str[])
{
	char *token;
	token=strtok(str," ");
	token=strtok(NULL," ");
	if(token==NULL)
	{
		printAll();
	}
	else
		printCount(atoi(token));
}
Example #6
0
void refreshScreen ( )
{
	char productsString[PRODUCTS_STRING_LENGTH + 1];
	int boxedCorrectProductCount = boxedProductCount(TRUE);
	int boxedDefectiveProductCount = boxedProductCount(FALSE);
	int droppedCorrectProductCount = droppedProductCount(TRUE);
	int droppedDefectiveProductCount = droppedProductCount(FALSE);

	getProductsString(productsString, PRODUCTS_STRING_LENGTH+1,
			CORRECT_PRODUCT_CHAR, DEFECTIVE_PRODUCT_CHAR);

	printf(SIMULATOR_PROMPT,
			COLOR_LABEL[getColor()],
			VALVE_STATE_LABEL[valveState(INLET_VALVE)],
			VALVE_STATE_LABEL[valveState(OUTLET_VALVE)],
			PRINTER_STATE_LABEL[printerState(PRINTR1)],
			PRINTER_STATE_LABEL[printerState(PRINTR2)],
			printCount(PRINTR1),
			printCount(PRINTR2),
			LAST_BOX_MISSING_LABEL[boxMissing()],
			(productsString[0] == 0 ? NONE_STRING : productsString),

			/*-- Product count table --*/
			/* 1st row */
			boxedCorrectProductCount,
			droppedCorrectProductCount,
			boxedCorrectProductCount + droppedCorrectProductCount,
			/* 2nd row */
			boxedDefectiveProductCount,
			droppedDefectiveProductCount,
			boxedDefectiveProductCount + droppedDefectiveProductCount,
			/* 3rd row */
			boxedCorrectProductCount + boxedDefectiveProductCount,
			droppedCorrectProductCount + droppedDefectiveProductCount,
			boxedCorrectProductCount + boxedDefectiveProductCount
				+ droppedCorrectProductCount + droppedDefectiveProductCount
			);
}
Example #7
0
main(){
	BstNode* root = NULL;
	int  i;
	FILE* f;
	char c;
	do{
		printf("\n1. Print File and Make Tree\n2. Print Count \n3. Print Thong Ke\n4. Exit");
		printf("\nChose: ");
		scanf("%d", &i); while(getchar()!= '\n');
		switch(i){
			case 1: root = readFile(f, root);
					break;
			case 2: printf("\nChar: ");
					scanf("%c", &c);while(getchar()!= '\n');
					printCount(root,c); break;
			case 3: printThongKe(root); break;
		}
	}while(i!= 4);

}
Example #8
0
static void printConfirmQuit(void)
{
    printf("\n");
    printCount();
    printf("Are you sure to quit? (y/N): ");
}
Example #9
0
int	ltpcounter(int a1, int a2, int a3, int a4, int a5,
		int a6, int a7, int a8, int a9, int a10)
{
	int		clientId = a1;
	int		maxBytes = a2;
#else
int	main(int argc, char **argv)
{
	int		clientId = (argc > 1 ? strtol(argv[1], NULL, 0) : 0);
	int		maxBytes = (argc > 2 ? strtol(argv[2], NULL, 0) : 0);
#endif
	IonAlarm	alarm = { 5, 0, showProgress, NULL };
	pthread_t	alarmThread;
	int		state = 1;
	LtpNoticeType	type;
	LtpSessionId	sessionId;
	unsigned char	reasonCode;
	unsigned char	endOfBlock;
	unsigned int	dataOffset;
	unsigned int	dataLength;
	Object		data;
	char		buffer[255];

	if (clientId < 1)
	{
		PUTS("Usage: ltpcounter <client ID> [<max nbr of bytes>]");
		PUTS("  Max nbr of bytes defaults to 2 billion.");
		return 0;
	}

	oK(_clientId(&clientId));
	if (maxBytes < 1)
	{
		maxBytes = 2000000000;
	}

	if (ltp_attach() < 0)
	{
		putErrmsg("ltpcounter can't initialize LTP.", NULL);
		return 1;
	}

	if (ltp_open(_clientId(NULL)) < 0)
	{
		putErrmsg("ltpcounter can't open client access.",
				itoa(_clientId(NULL)));
		return 1;
	}

	ionSetAlarm(&alarm, &alarmThread);
	isignal(SIGINT, handleQuit);
	oK((_running(&state)));
	while (_running(NULL))
	{
		if (ltp_get_notice(_clientId(NULL), &type, &sessionId,
				&reasonCode, &endOfBlock, &dataOffset,
				&dataLength, &data) < 0)
		{
			putErrmsg("Can't get LTP notice.", NULL);
			state = 0;
			oK((_running(&state)));
			continue;
		}

		switch (type)
		{
		case LtpExportSessionCanceled:
			isprintf(buffer, sizeof buffer, "Transmission \
canceled: source engine " UVAST_FIELDSPEC ", session %u, reason code %d.",
					sessionId.sourceEngineId,
					sessionId.sessionNbr, reasonCode);
			writeMemo(buffer);
			if (data)
			{
				ltp_release_data(data);
			}

			break;

		case LtpImportSessionCanceled:
			oK(_sessionsCanceled(1));
			isprintf(buffer, sizeof buffer, "Reception canceled: \
source engine " UVAST_FIELDSPEC ", session %u, reason code %d.",
					sessionId.sourceEngineId,
					sessionId.sessionNbr, reasonCode);
			writeMemo(buffer);
			break;

		case LtpRecvGreenSegment:
			isprintf(buffer, sizeof buffer, "Green segment \
received, discarded: source engine " UVAST_FIELDSPEC ", session %u, \
offset %u, length %u, eob=%d.", sessionId.sourceEngineId, sessionId.sessionNbr,
					dataOffset, dataLength, endOfBlock);
			writeMemo(buffer);
			ltp_release_data(data);
			break;

		case LtpRecvRedPart:
			oK(_blocksReceived(1));
			oK(_bytesReceived(dataLength));
			ltp_release_data(data);
			break;

		default:
			break;
		}

		if (_bytesReceived(0) >= maxBytes)
		{
			state = 0;
			oK((_running(&state)));
		}
	}

	ionCancelAlarm(alarmThread);
	writeErrmsgMemos();
	printCount();
	PUTS("Stopping ltpcounter.");
	ltp_close(_clientId(NULL));
	ltp_detach();
	return 0;
}
Example #10
0
void menu(char ***array, int *wordCount, int *capacity)
{
  int exit;
  char option;
  char word[WORD_LENGTH];
  
  exit = 0;
  do 
  {
    printf("\nMenu\n");
    printf("'S'earch, 'I'nsert, 'R'emove, 'C'ount, 'P'rint, 'Q'uit\n");
    scanf("%c", &option);
    /* takes in char + newline character
       see "newline handler" below
    */
    if (option == 's' || option == 'S')
    {
      /* call search() */
      printf("\nSearch\n");
      searchWord(array, wordCount);
    } 
    else if (option == 'i' || option == 'I') 
    {
      /* call insert() */
      printf("\nInsert\n");
      printf("\nEnter a word: ");
      scanf("%s", word);
      insertWord(array, wordCount, word, capacity);
      printf("\nWord inserted.\n");
    } 
    else if (option == 'r' || option == 'R') 
    {
      /* call remove() */
      printf("\nRemove\n");
      removeWord(array, wordCount);
    } 
    else if (option == 'c' || option == 'C') 
    {
      /* call count() */
      printf("\nCount\n");
      printCount(*wordCount);
    } 
    else if (option == 'p' || option == 'P') 
    {
      printf("\nPrint\n");
      printArray(*array, *wordCount);
    } 
    else if (option == 'q' || option == 'Q') 
    {
      exit = 1;
    } 
    else 
    {
      /* invalid entry */
      printf("\nInvalid Entry, returning to main menu\n");
    }
    /* newline handler */
    while (option != '\n') 
    {
      scanf("%c", &option);
    }
  } 
  while (exit == 0);
}