static
void DoTest()
{
    int num_items=64;
    My402List list, list2;

    memset(&list, 0, sizeof(My402List));
    memset(&list2, 0, sizeof(My402List));
    (void)My402ListInit(&list);
    (void)My402ListInit(&list2);

    CreateTestList(&list, num_items);
    RandomShuffle(&list, num_items);
    FindAllInList(&list, num_items);
    CopyTestList(&list, &list2);

    BubbleSortForwardList(&list, num_items);
    if (gnDebug > 0) PrintTestList(&list, num_items);

    BubbleSortBackwardList(&list2, num_items);
    if (gnDebug > 0) PrintTestList(&list2, num_items);

    CompareTestList(&list, &list2, num_items);

    My402ListUnlinkAll(&list);
    My402ListUnlinkAll(&list2);
}
void Initialize()
{
	My402ListInit(&Q1PacketList);
	My402ListInit(&Q2PacketList);
	My402ListInit(&token_bucket_list);	
	sigemptyset(&signal_set);
	sigaddset(&signal_set, SIGINT);
}
Beispiel #3
0
void process(char * file_name)
{
	struct stat info;
	stat(file_name, &info);
	if(S_ISDIR(info.st_mode))
		print_error("the path is a directory");


    char buffer[MAX_LINE_LENGTH + 2];
    buffer[MAX_LINE_LENGTH] = '\0';

	My402List list;
	memset(&list, 0, sizeof(My402List));
	(void)My402ListInit(&list);

	FILE * file;
	if(file_name)
	{
	    if((file = fopen(file_name, "r")) == NULL)
			print_error("cannot open file");
	}
	else
		file = stdin;

	while(!feof(file))
	{
	   	if(fgets(buffer, MAX_LINE_LENGTH + 2, file))
	   		insert_list(&list, parse_file(buffer));
	}
	fclose(file);
   	print_list(&list);

}
int main(int argc, char *argv[])
{
    FILE *fp = NULL;
    My402List *myList = NULL;
    myList = (My402List *)malloc(sizeof(My402List));
    char *dir = argv[2];
    DIR* directory = NULL;
    if(myList == NULL) {
			fprintf(stderr,"Memory allocation for the list failed!");
			PrintErrorMessage();
	}
	(void)My402ListInit(myList);
	if(argc < 2) {
		fprintf(stderr,"Error: Too less arguments\n");
		exit(1);
	} if(argc > 3) {
		fprintf(stderr,"Error: Too many arguments\n");
		exit(1);
	}	
	if(argv[1][0] == '-') {
		fprintf(stderr,"Cannot have \'-\' in the argument\n");
		exit(1);
	}
	if(argc >= 2) {
		if(strcmp(argv[1],"sort") == 0) {
			if(argc == 2) {
				fp = stdin;
				ReadFileInput(fp,myList);
				BubbleSortForwardList(myList);
				PrintList(myList);
				fclose(fp);
			} 
			if(argc == 3) {
				directory = opendir(dir);
				if(directory != NULL)
				{
					closedir(directory);
					fprintf(stderr,"Error: Given path is a directory\n");
					exit(1);
				}    
				fp = fopen(argv[2],"r");
				if(fp==NULL) {
						perror("Error ");
						exit(1);
				} 
				ReadFileInput(fp,myList);
				fclose(fp);
				BubbleSortForwardList(myList);
				PrintList(myList);
			}
		} else {
			fprintf(stderr,"Error: \'sort\' should be the second argument\n");
			exit(1);
		}
	}
	return 0;
}
int main(int argc , char*argv[]){
    My402List node ;
    FILE *fp = NULL;
    struct stat statbuf;
    
    
    
    if(argc != 2 && argc != 3 ){
        fprintf(stderr, "Please enter correct command- warmup1 sort [tfile]\n");
        exit(1);
    }
    
    if(strcmp(argv[1],"sort") != 0){
        fprintf(stderr, "Please enter correct command- warmup1 sort [tfile]\n");
        exit(1);
    }

    
    if(argc == 2){
        fp = stdin;
                    
    }
    
    
    else if(argc == 3){
        fp = fopen(argv[2], "r");
        if(fp == NULL){
            fprintf(stderr, "File \"%s\" not found\n",argv[2]);
            exit(1);
        }
        
        stat(argv[2], &statbuf);
        
        if(S_ISDIR(statbuf.st_mode)){
           fprintf(stderr, "\"%s\" is a directory\n",argv[2]);
            exit(1);
        }
        
        
    }
    
    
    memset(&node,0,sizeof(My402List));
    
    if(!My402ListInit(&node)){
        fprintf(stderr,"Error while init!!\n");
    }
    if(!ReadInput(fp,&node)){
        fprintf(stderr,"Error while reading input!\n");
    }
    
    PrintStatement(&node);
    
    return 0;
    
}
void My402ListUnlinkAll(My402List *list){
	if(list != NULL){
		My402ListElem *i = list -> anchor.next;
		My402ListElem *temp = NULL;
		while(i != list -> anchor.prev){
		    temp = i;
		    i = i -> next;
		    free(temp);
		}
		free(i);
		My402ListInit(list);
	}
}
int main(){
	
	int i=100;
	int j=0;
	int temp = -1;
	int *pKey = &temp;
	My402List list;
	My402ListElem *current = NULL; 
	My402List *pList = NULL;	
	pList = &list;		

	My402ListInit(pList);	
	int *a=(int *)malloc(NUM_MEMBERS*sizeof(*a));		
	if(a == NULL){
		NL	
		printf("Can not allocate memory for the data");	
		NL
	}
Beispiel #8
0
/**
 * @brief Create sender list
 *
 */
void create_list(char *data_ptr, My402List *list, const char *list_type){
    // Initialize the data list
    if (My402ListInit(list)==0){
        exit(1);
    }

    // Iterate and add nodes with seq_num and mem address
    vlong seq_num = 0;
    for (;seq_num<globals.config.total_size; seq_num += globals.config.packet_size){
        struct node *data_node = malloc(sizeof(struct node));
        data_node->seq_num = seq_num;
        data_node->mem_ptr = data_ptr + seq_num;
        // To handle scenario where the last packet is of size less then
        // required
        vlong size = globals.config.total_size - seq_num > globals.config.packet_size ? globals.config.packet_size : globals.config.total_size - seq_num;
        // size in bytes
        data_node->size = size;

        My402ListElem *link_node;
        if (My402ListAppend(list , data_node, &link_node)==0)
	    list_error("Append Failed");

        //DBG("MEM PTR = %p, SEQ_NUM = %llu", data_node->mem_ptr, data_node->seq_num);

        // Check if DATA or NACK list
        // Add the linked list node pointer to the hashmap node
        if (strcmp(list_type, DATA) == 0) {
            // DATA list
            hashed_link *hash_node = malloc(sizeof(hashed_link));
            hash_node->seq_num = data_node->seq_num;
            hash_node->data_node_ptr = link_node;
            add_hashl(hash_node);
        }
        else {
            // NACK list
            hashed_link *hash_node = (hashed_link *)(find_hashl(data_node->seq_num));
            if (!hash_node) {
                DBG("This should never happen");
                exit(1);
            }
            hash_node->nack_node_ptr = link_node;
        }
    }
}
Beispiel #9
0
int main(int argc,char* argv[])
{
    FILE* fp=NULL;
    //printf("no of argc=%d\n",argc);
    fp=argChk(argc,argv);

    if(fp == NULL || fp == 0)
	{
		fprintf(stderr, "Quitting the Program because - %s\n", strerror(errno));
		exit(0);
	}
 
    
    My402List *list;        //------creating a list-----//
    list=(My402List*)malloc(sizeof(My402List));
    
    if(!My402ListInit(list))
    {
        fprintf(stderr,"Error: Error in Initializing the list\n");
        exit(0);
    }
        if(!Read_input(fp,list))
    {
        printf("error\n");
        exit(0);
    }

        if(list->num_members==0)
        {
            fprintf(stderr,"Error:Invalid input\n");
            exit(0);
        }
        sort(list);
        display(list);
        fclose(fp);
    cleanup(list);
       
        return TRUE;
    
        
        
        
}
static
void RandomShuffle(My402List *pList, int num_items)
{
    int i=0;
    My402List list2;
    My402ListElem *elem=NULL;

    memset(&list2, 0, sizeof(My402List));
    (void)My402ListInit(&list2);

    for (i=0; i < num_items; i++) {
        int j=0, idx=0, num_in_list=num_items-i;
        void *obj=NULL;

        idx = RandomIndex(num_in_list);
        for (elem=My402ListFirst(pList); elem != NULL; elem=My402ListNext(pList, elem)) {
            if (j == idx) {
                break;
            }
            j++;
        }
        if (elem == NULL) {
            fprintf(stderr, "Unrecoverable error in RandomShuffle().\n");
            exit(1);
        }
        obj = elem->obj;
        My402ListUnlink(pList, elem);
        (void)My402ListAppend(&list2, obj);
    }
    if (!My402ListEmpty(pList)) {
        fprintf(stderr, "List not empty in RandomShuffle().\n");
        exit(1);
    }
    for (elem=My402ListFirst(&list2); elem != NULL; elem=My402ListNext(&list2, elem)) {
        (void)My402ListAppend(pList, elem->obj);
    }
    My402ListUnlinkAll(&list2);
}
Beispiel #11
0
/**
 * @brief Create list
 *        recv_data_list
 *        recv_nack__list
 *        only sequence number is added
 */
void create_recv_list(My402List *list, const char *list_type){
    // Initialize the data list
    if (My402ListInit(list)==0){
        exit(1);
    }

    // Iterate and add nodes with seq_num and mem address
    vlong seq_num = 0;
    for (;seq_num<globals.config.total_size; seq_num += globals.config.packet_size){
        struct node *data_node = malloc(sizeof(struct node));
        data_node->seq_num = seq_num;
        data_node->mem_ptr = NULL;

        My402ListElem *link_node;
        if (My402ListAppend(list , data_node, &link_node)==0)
	    list_error("Append Failed");

        // Check if DATA or NACK list
        // Add the linked list node pointer to the hashmap node
        if (strcmp(list_type, DATA) == 0) {
            // DATA list
            hashed_link *hash_node = malloc(sizeof(hashed_link));
            hash_node->seq_num = data_node->seq_num;
            hash_node->data_node_ptr = link_node;
            add_hashl(hash_node);
        }
        else {
            // NACK list
            hashed_link *hash_node = (hashed_link *)(find_hashl(data_node->seq_num));
            if (!hash_node) {
                DBG("This should never happen");
                exit(1);
            }
            hash_node->nack_node_ptr = link_node;
        }
    }
}
Beispiel #12
0
/* This read file function read file character by character */
void read_file(char * file_name)
{
	FILE *fp;
	// MAX_LINE_LENGTH = 1024; MAX_TIMESTAMP_LENGTH = 10; MAX_AMOUNT_LENGTH = 10
	char ch, type, timestamp[MAX_TIMESTAMP_LENGTH + 1], amount[MAX_AMOUNT_LENGTH + 1], description[MAX_LINE_LENGTH];
	// status indicate which kind data currently read, 0:type; 1:timestamp; 2:amount; 3:description
	int status = 0, timestamp_i, amount_i, amount_t, description_i, description_max;
	// Doubly-linked circular list
	My402List list;
	memset(&list, 0, sizeof(My402List));
	(void)My402ListInit(&list);

	if((fp = fopen(file_name,"r")) == NULL)
		print_error("cannot open file");

	while((ch = fgetc(fp)) != EOF)
	{
		switch(status)
		{
			case 0: // read type
				if(ch != '-' && ch != '+')
					print_error("undefined transcation type");
				else
				{
					type = ch;
					ch = fgetc(fp);
					if(ch != '\t' && ch != EOF)
						print_error("wrong format of file");
					else
						status++;
				}
				break;
			case 1: // read timestamp
				timestamp_i = 0;
				while(ch != '\t' && ch != EOF)
				{
					if(timestamp_i >= MAX_TIMESTAMP_LENGTH)
						print_error("timestamp is too large");
					if(ch < '0' || ch > '9')
						print_error("timestamp must be number");
					timestamp[timestamp_i++] = ch;
					ch = fgetc(fp);
				}
				timestamp[timestamp_i] = '\0';
				status++;
				break;
			case 2: // read amount
				amount_i = 0;
				amount_t = 0;
				while(ch != '\t' && ch != EOF)
				{
					if(amount_i >= MAX_AMOUNT_LENGTH)
						print_error("amount is too large");
					if(ch >= '0' && ch <= '9')
					{
						amount[amount_i++] = ch;
						ch = fgetc(fp);
					}
					else if(ch == '.')
					{
						if(++amount_t > 1)
							print_error("wrong format of amount");
						else
						{
							// skip the '.' symbol
							// amount[amount_i++] = ch;
							ch = fgetc(fp);
						}
					}
					else
						print_error("wrong format of amount");
				}
				amount[amount_i] = '\0';
				status++;
				break;
			case 3: // read description
				description_i = 0;
				description_max = MAX_LINE_LENGTH - amount_i - timestamp_i;
				while(ch != '\n' && ch != EOF)
				{
					if(description_i >= description_max)
						print_error("description is too long");
					if(ch == '\t')
						print_error("wrong format of file");
					description[description_i++] = ch;
					ch = fgetc(fp);
				}
				description[description_i] = '\0';

				encapsulate_data(type, timestamp, amount, description);

				status = 0;
				break;
			default:
				print_error("parse file error");
				break;
		}
	}
	fclose(fp);
}
Beispiel #13
0
int main(int argc, char *argv[]){

	int isInsert = FALSE;
	My402SortElem *currentSortElem = NULL;	
	My402List list;
	My402ListInit(&list);
	My402List *pList = &list;	
	FILE *fp = stdin;
	char *fileName = {"\0"};
	char *pSortElem[4];
	pSortElem[0] = (char *)malloc(2*sizeof(char)); // 1 for +/- and the other for '\0'	
	pSortElem[1] = (char *)malloc(11*sizeof(char));//MAX 10, +1 for terminating char
	pSortElem[2] = (char *)malloc(sizeof(int));
	pSortElem[3] = (char *)malloc(sizeof(1024));
	
	//TODO: output to stdout and error to stderr
		
	//FIXME: re-check the initialization part	
	
	char buf[CHAR_LIMIT+26] = {'\0'}; 	
	char *start_ptr = buf;
	char *tab_ptr = NULL;
	int tabNumber = 0;
	char *str = (char *)malloc(sizeof(1050));
	memset(str,sizeof(str),'\0');
	char *transDesc = (char *)malloc(sizeof(1024));	
	memset(transDesc, sizeof(transDesc), '\0');

	//FIXME: user should be ketp asking or program should exit?
	//FIXME: modify according to the makefile	
	
	if(!(argc == 2 || argc == 3) 
		||(argc>1 && strcmp("sort",argv[1]) != 0)
		||(argc==3 && 
			!( isalpha(argv[2][0]) != 0 || argv[2][0] == '_'|| argv[2][0] == '/')
		  )
	
	){
		fprintf(stderr,"\nmalformed command");
		fprintf(stderr, "\nPlease enter the command in either of the following formats:");
		fprintf(stderr, "\n\twarmpup1 sort tfile");
		fprintf(stderr, "\n\tor");
		fprintf(stderr, "\n\twarmup1 sort\n\n");	
		return 0;
	}
	
	//FIXME: when working with make file	
	if(argc == 3){
		fileName = argv[2];		
		fp = fopen(fileName,"r");
	}
	if(fp == NULL){
		//FIXME: Is there a case for unable to open stdin?
		//FIXME: input file is not in the correct format 
		fprintf(stderr, "\nUnable to open the file: %s. Please check the given file name and its path and try again!\n", argv[2]);
		perror(NULL);	
		return 0;	
	}

	while((str = fgets(buf, sizeof(buf), fp)) != NULL){
			//printf("\n complete string length:%d\n", strlen(str));	
			if(strlen(buf)==0 || buf[0] == '\n'){
				fprintf(stderr,"\nThere is an empty line present in the file");
				fprintf(stderr,"\nSo the program aborts now!\n");	
				return 0;
			}
			if(isTabsOK(buf) == FALSE){
				fprintf(stderr,"\nThere is a line present in the file with more than 3 TABS.\nEach line in the file must exactly have three TABS");
				fprintf(stderr,"\nSo the program aborts now!\n");	
				return 0;
			}	
			if(strlen(str)>CHAR_LIMIT+1){ //+1 for new line char
				fprintf(stderr, "\nThe line has more than %d characters, so the program aborts now! \n", CHAR_LIMIT);	
				return 0;
			}else{
			//Parse and see if it is malformed	
				//printf("\nStruct starts\n");	
				
				start_ptr = str;	
				for(tabNumber=0; tabNumber<3; tabNumber++){
					tab_ptr = strchr(start_ptr,'\t');
					if(tab_ptr == NULL){
						fprintf(stderr,"\nEach line in the file must exactly have three TABs");	
						fprintf(stderr, "\nThe string is malformed, so the program aborts now! \n");	
						return 0;
					}
					if(tab_ptr != NULL){
						*tab_ptr = '\0';	
					}		
					//FIXME: substrings must not be NULL
					//printf("%s ",substring(buf,start_ptr));
					pSortElem[tabNumber] = substring(buf, start_ptr);
					start_ptr = tab_ptr+1;	
				}
				transDesc = substring(buf, start_ptr);
				if(strlen(transDesc) == 0){
				
					fprintf(stderr,"\nTransaction Description can not be empty.");
					fprintf(stderr, "\nThe string is malformed, so the program aborts now! \n");	
					return 0;
				}	
				//printf("%s", substring(buf,start_ptr));
				pSortElem[3] = substring(buf, start_ptr);	
				//FIXME: verify each field has the right data
				if(verifySortElem(pSortElem) == FALSE){
					fprintf(stderr, "\nThe string is malformed, so the program aborts now! \n");	
					return 0;
				}	
				currentSortElem = createSortElem(pSortElem);	
				isInsert = insertionSort(pList, currentSortElem);
				if(isInsert == FALSE){
					fprintf(stderr, "\nso the program aborts now! \n");	
					return 0;	
				}
				/*
				if(strchr(str,'\n') == NULL){
					break; //EOF reached	
				}*/
			}	
		
		//}else{
			//printf("\nThe last character: %c", str[strlen(str)-1]=='\n'?'t':'f');	
			//printf("\n strlen(buf)=%d", (int)strlen(buf));	
			//printf("\nThe line has more than %d characters, so the program aborts now! \n", CHAR_LIMIT);	
			//return 0;
		//}
	}
	//printf("\n hit the EOF..came out\n");	
	fclose(fp);	
	//printList(pList);
	//printf("\n The output starts here..");
	printOutput(pList);
	unlinkSortElements(pList);
	//printf("\n The output ends here..");
	
	return 0;
}
Beispiel #14
0
void *Service(void* arg){
    My402ListInit(&Q2_node);
    double time_in_system = 0.0;
    
    while(1){
        My402ListElem *first_elem = NULL ;
        Packet_desc *p = NULL;
        
        
        if(total_packets_prod == num && My402ListEmpty(&Q2_node) && My402ListEmpty(&Q1_node)){
        	pthread_cond_broadcast(&serverQ);
        	 break;
    
		}
           
        
        pthread_mutex_lock(&lock);
        
        while(curr_q2_size == 0 && !interrupt_called){
            pthread_cond_wait(&serverQ, &lock);
        }
        if((total_packets_prod == num && My402ListEmpty(&Q2_node) && My402ListEmpty(&Q1_node)) || interrupt_called){
            pthread_exit(0);
        }
        
        first_elem = My402ListFirst(&Q2_node);
        
        if(first_elem->obj == NULL){
            fprintf(stderr,"Error: Obj is NULL");
            pthread_exit(0);
        }
        
        p = (Packet_desc*)first_elem->obj;
        
        
        DequePacket(p,first_elem);
        p->S_time_enters = GetMTimeOfDay();
        pthread_mutex_unlock(&lock);
        
        
        usleep(p->ser_time*THOUSAND);
        
        pthread_mutex_lock(&lock);
        
        packet_served++;
        
        p->total_S_time = GetMTimeOfDay()- p->S_time_enters;
        time_in_system = GetMTimeOfDay()- p->Q1_time_enters;
        sys_variance += time_in_system * time_in_system ;
        
        /* Calculate total time for the packets served */
        total_ser_time += p->total_S_time;
        total_sys_time += time_in_system;
        time_in_Q1 += p->total_Q1_time;
        time_in_Q2 += p->total_Q2_time;
        
        
        fprintf(stdout, "%012.3lfms: p%d departs from S, service time = %.3fms, time in system = %.3fms\n",GetMTimeOfDay(), p->name_ID,p->total_S_time,time_in_system);
        
        free(p);
        
        pthread_mutex_unlock(&lock);
        
    }
    
    return 0;
}
Beispiel #15
0
int main(int argc, char *argv[])
{
    int res = 0;
    /*
     * Check if the number of arguments passed 
     * if less than 2 return error with the
     * expected format.
     */
    if(argc < 2 ){
        fprintf(stderr, "Missing the sort command\n");
        return 0;
    }
    
    /*
     * Make sure the second argument 
     * is sort
     */
    if(strncmp(argv[1], "sort", 4)){
        fprintf(stderr, "Wrong command, please enter \"warmup1 sort [tfile]\"\n");
        return 0;
    }
    
    /*
     * If file is given:
     * Check if the file is
     *  Accessible
     *  Valid
     *  Not a directory
     */

    if(argc == 3){
        if(argv[2]){
            if(!checkFile(argv[2])){
                    return 0;
            }
        }
    }

    /*
     * Initialize the circular list
     */

    My402List list;
    memset(&list, 0, sizeof(My402List));
    res = My402ListInit(&list);

    if(!res) {
        fprintf(stderr, "Error during Initialization of the list\n");
        exit(0);
    }

    /*
     * We will now call the parse function
     */
    if(!Input(&list, argv[2])) {
        FreeObjMem(&list);
        My402ListUnlinkAll(&list);
        exit(0);
    }
    
    /*
     * Output the balance
     */
    Output(&list);

    /*
     * free the memory space used for all the 
     * objects
     */
    FreeObjMem(&list);

    /*
     * Unlink all the list elements
     */
    My402ListUnlinkAll(&list);

    exit(0);
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    /* Packet Thread */
    /* Initialize the mutex */
    pthread_mutex_init(&m, 0);

    int i;
    char *lambda = "0.5";
    char *mu = "0.35";
    char *r = "1.5";
    char *B = "10";
    char *P = "3";
    char *n = "20";
    char *FILENAME = NULL;
    AVAILABLE = 0;
    DROPPED = 0;
    DROPPED_PKT = 0;
    TOTAL = 0;
    TOTAL_SERVED = 0;
    SERVER_DIE = 0;

    /* Read Options */
    for(i=1;i<argc;i=i+2){
        if (i%2!=0 && argv[i][0]=='-'){
            if ((strcmp(argv[i]+1, "lambda") == 0) && ((i+1)<argc)){
                lambda = argv[i+1];
                if(check_num(lambda)== -1){
                    fprintf(stderr, "Value of lambda is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if ((strcmp(argv[i]+1, "mu") == 0) && ((i+1)<argc)){
                mu = argv[i+1];
                if(check_num(mu)== -1){
                    fprintf(stderr, "Value of mu is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if ((strcmp(argv[i]+1, "r") == 0) && ((i+1)<argc)){
                r = argv[i+1];
                if(check_num(r)== -1){
                    fprintf(stderr, "Value of r is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if ((strcmp(argv[i]+1, "B") == 0) && ((i+1)<argc)){
                B = argv[i+1];
                if(isNum(B)==-1){
                    fprintf(stderr, "Value of B is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if((strcmp(argv[i]+1, "P") == 0) && ((i+1)<argc)){
                P = argv[i+1];
                if(isNum(P) == -1){
                    fprintf(stderr, "Value of P is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if ((strcmp(argv[i]+1, "n") == 0) && ((i+1)<argc)){
                n = argv[i+1];
                if(isNum(n)==-1){
                    fprintf(stderr, "Value of n is not a number.\n");
                    exit(0);
                }
                continue;
            }
            else if ((strcmp(argv[i]+1, "t") == 0) && ((i+1)<argc)){
                FILENAME = argv[i+1];
                continue;
            }
        }
        fprintf(stderr, "Wrong command line argument\n");
        exit(0);
        break;
     }

    /*Allocate memory to list*/
    Q1 = malloc(sizeof(My402List));
    Q2 = malloc(sizeof(My402List));
    /*Initilialize the list*/
    My402ListInit(Q1);
    My402ListInit(Q2);

    /* Block Signal from Main thread */
    block_signal();

    if(FILENAME!=NULL){
        FILE *fp = fopen(FILENAME, "r");
        if(fp==NULL){
            perror("Error: Unable to open the file ");
            exit(0);
        }
        fclose(fp);
    }

   
    print_input(lambda, mu, FILENAME, r, B, P, n);
    /* Create packet thread */

    fprintf(stdout, "\n");
    /* Initialize the stats */ 
    init_stats();

    struct timeval current = diff_timeval(START_TIMEVAL, PKT_BEFORE);
    fprintf(stdout, "%08llu.%03ldms: emulation begins\n",
            toMilliSeconds(current), current.tv_usec%MILLI);

    /* Create threads */
    create_packet_thread(lambda, mu, FILENAME, r, B, P, n);

    /* Print statistics */
    //print_stats();

    return(0);
}
Beispiel #17
0
void *Arrival(void* arg){
    
    
    int i =0;
    double prev_itime = 0 ;
    double inter_a_time = 0.0;
    Packet_desc *p = NULL;
    
    //Init the list
    My402ListInit(&Q1_node);
    
    
    //create packet
    while(i != num) {
        
        p = (Packet_desc*)malloc(sizeof(Packet_desc));
        
        if(fp != NULL){
            ReadFile(p);
        }
        else{
            p->int_time = 1/lamda*THOUSAND ; // interarrival time
            p->tokens = P;
            p->ser_time = 1/mu*THOUSAND; // service time
        }
        p->name_ID = ++i;
        
        
        usleep(p->int_time*THOUSAND);
        
        inter_a_time = GetMTimeOfDay()- prev_itime;
        
        prev_itime = GetMTimeOfDay() ;
        
        total_i_a_time += inter_a_time;
        
        pthread_mutex_lock(&lock);
        
        if(p->tokens > B){
            
            fprintf(stdout, "%012.3lfms: p%d arrives, needs %d tokens, inter-arrival time = %.3fms, dropped\n",GetMTimeOfDay(),p->name_ID,p->tokens, inter_a_time);
            packets_drop++;
            total_packets_prod++;
            free(p);
            
            pthread_mutex_unlock(&lock);
            
            continue;
        }
        
        fprintf(stdout, "%012.3lfms: p%d arrives, needs %d tokens, inter-arrival time = %.3fms\n",GetMTimeOfDay() ,p->name_ID,p->tokens,inter_a_time);
        
        total_packets_prod++;
        
        pthread_mutex_unlock(&lock);
        
        pthread_mutex_lock(&lock);
        
        packet_arrived++;
        
        //critical section
        
        EnquePacket(p);
        
        ProcessPacket();
        
        pthread_mutex_unlock(&lock);
    }
    
    if(filename){
        fclose(fp);
    }
    
    return 0;
}
Beispiel #18
0
int main(int argc, char *argv[])
{
		My402List list;
   // My402ListElem *elem=NULL;

    memset(&list, 0, sizeof(My402List));
    (void)My402ListInit(&list);
	
	//Transact t;
	
	
			FILE *fptr;
			//char address[100]="test.tfile";
		char buf[200];
	//printf("ARGC: %d\n",argc);
	if(argc<2)//if sort is missing
	{
		printf("Malformed command\n");
		exit(0);
	}
	if((strcmp(argv[1],"sort")))//if second argument is not 'sort'
	{
		printf("Malformed command\n");
		exit(0);
	}
	if(argc==2)
	{
			fptr=stdin;			
	}
	if(argc==3)
	{		
		if(!strstr(argv[2],".tfile"))
		{
			printf("Could not open file: %s\n",argv[2]);
			printf("Input file either a directory or not in correct format\n");
			exit(0);
		}
		
		fptr=fopen(argv[2], "rt"); 		
	}
    if (fptr==NULL) 
    { //perror("Error:");
       // printf("%s",argv[2]);
        printf("Could not open file: %s!\n",argv[2]); // error in opening file
		printf("%s\n", strerror(errno));
		exit(0);
		//perror("Error:");
        // getch();
        return 1; 
    }
    else
    {
	
		while(fgets(buf, sizeof(buf), fptr) != NULL)
		{
			// if (fgets(buf, sizeof(buf), fptr) == NULL)
		// {
		  // /* end of file */
		  // break;
		// } 
	//else 
	//	{
			//printf("%s",argv[3]);
			//printf("==%s==",buf);
			//printf("COMING TILL HERE!!!\n");
			if(strlen(buf)>1024)
			{
				printf("Invalid input, line is too long\n");
				exit(0);
			}
			long timeint;
			char timec[30];//change size 
			char op;
			//float amt;
			double a=0.0;
			char desc[40];//change size!!!
			//else 
			{
				
				Transact *t;
				t=malloc(sizeof(struct data));
				//printf("BUF: %s\n",buf);
				int i;
				
				char *start_ptr = buf;
				if(!strchr(start_ptr,'\t'))
				{
					printf("Invalid input, not enough info\n");
					exit(0);
				}
				//char *nline_ptr;
				if(strchr(start_ptr,'\r'))
				{
				char *nline_ptr = strchr(start_ptr,'\r');
				*nline_ptr++='\0';
				}
				if(strchr(start_ptr,'\n'))
				{
				char *nline_ptr = strchr(start_ptr,'\n');
				*nline_ptr++='\0';
				}
				char *tab_ptr = strchr(start_ptr, '\t');
				if (tab_ptr != NULL) 
				{
				  *tab_ptr++ = '\0';
				 // printf("%s\t",start_ptr);
				  op=start_ptr[0];
						//printf("OPERATOR= %c\n",op);
						t->op=op;
						if(((op!='+')&&(op!='-')))
						{
							printf("Invalid input with Operator: %c\n",t->op);
							exit(1);
						}
					//	printf("%c\t",t->op);
				}
				for(i=0;i<3;i++)
				{
					start_ptr = tab_ptr;
					// if(!strchr(start_ptr,'\t'))
					// {
						// printf("Invalid input, not enough info2\n");
						// //exit(0);
					// }
						tab_ptr = strchr(start_ptr, '\t');
					//nline_ptr= strchr(start_ptr, '\n');
					
					if ((tab_ptr != NULL)) 
					{
					  *tab_ptr++ = '\0';
					  
					}
					if(i==0)
					{
												
						if(strlen(start_ptr)>=11)
						{
							printf("Invalid input in timestamp: %s\n",start_ptr);
							exit(0);
						}
						if(!((atoi(start_ptr)>0)&&(atoi(start_ptr)<time(NULL))))
						{
							printf("Invalid input in timestamp\n");
							exit(0);
						}
					
						 timeint=atol(start_ptr);
						t->ltime=timeint;
						//printf("--TIME: %lu\t",timeint);
						strcpy(timec,ctime(&timeint));//time is stored in array time
						
					}
					else if(i==1)
					{
						//if(start_ptr[strlen(start_ptr)-3]
					  if(strlen(start_ptr)<4)//min should have one digit before decimal, 2 after and decimal itself
					  {
						printf("Invalid input, not enough digits or decimal\n");
						exit(0);
					  }
					 // if((start_ptr[strlen(start_ptr)-3]!='.')&&(start_ptr[0]=='.'))
					// printf("%c",start_ptr[strlen(start_ptr)-3]);
					  if((start_ptr[strlen(start_ptr)-3]!='.'))
					  {
						printf("Invalid input, does not contain decimal or enough digits after decimal: %s\n",start_ptr);
						exit(0);
					   }
					  if(start_ptr[0]=='.')
					  {
						printf("Invalid input, no digit before decimal\n");
						exit(0);
					  }
						a=atof(start_ptr);
						
						if((a>10000000)||(a<0))
						{
							printf("Invalid input with Amount\n");
							exit(1);
						}
						t->amt=a*100;
						
						
	
						// sprintf(chk, "%0.2f",a);
						// printf("STRING: %s\n",chk);
						// printf("Invalid input, does not contain decimal: %c\n",chk[strlen(chk)-2]);
						// // if(chk[strlen(chk)-3]!='.')
							// // printf("Invalid input, does not contain decimal: %c\n",chk[strlen(chk)-2]);
						
						//printf("AMOUNT: %f--\t",a);
						//printf("%f\t",a);
						//printf("%d\t",t->amt);
					}
					else if(i==2)
					{
						while(isspace(*start_ptr)) 
							start_ptr++;

					    if(*start_ptr == 0)  // All spaces?
						{
							printf("Invalid input..No description\n");
							exit(0);
						}
						if(strlen(start_ptr)>24)
							strncpy(desc,start_ptr,23);
						else
							strcpy(desc,start_ptr);
						
						strcpy(t->desc,desc);
						//t->desc=desc;
						//printf("Description%s",start_ptr);
						//printf("%s\n",t->desc);
					}
				//	printf("%s\t",start_ptr);
				}
				//printf("\n");
				if(checkTime(&list,t->ltime))//1 returned if same exists
				{
					printf("Two same timestamps detected\n");
					exit(0);
				}
				//printf("CTIME:%s",ctime(&time));	
				//printf("Appending\n");
				My402ListAppend(&list,t);
			
			}
		 //}
	  }//while loop
	}
	BubbleSortForwardList(&list,list.num_members);
	PrintTestList(&list,list.num_members);
  
 
    return(0);
}
Beispiel #19
0
int main(int argc, char **argv)
{
	long t1=1, t2=2, t3=3;
	pthread_t arrThread, serThread, tokThread;
	long total_emulation_time;

	// Setting to default values

	lambda = 0.5;
	mu = 0.35;
	r = 1.5;
	P = 3;
	B = 10;
	num_packets = 20;

	token_bucket = 0;
	server_die = 0;
	token_die = 0;

	avg_pkt_q1 = avg_pkt_q2 = avg_pkt_s = 0;
	// Done

	// Initialize Queues
	
	My402ListInit(&queue1);
	My402ListInit(&queue2);

	pthread_mutex_init(&my_mutex,NULL);
	pthread_cond_init(&queue2_cond,NULL);

	parseCommandline(argc,argv);

	tokenarrival = (long)((1/r)*1000000);
	pkts_to_arrive = num_packets;


	pthread_create(&arrThread, NULL, arrivalThread,(void *)t1);
	pthread_create(&tokThread, NULL, tokenThread,(void *)t2);
	pthread_create(&serThread, NULL, serverThread, (void *)t3);

	temulation_start = tastart = ttstart =  getinstanttime();
	PrintStat(getinstanttime());
	fprintf(stdout, "Emulation Begins\n");



	pthread_join(arrThread, NULL);
	pthread_join(tokThread, NULL);
	pthread_join(serThread, NULL);

	temulation_end = getinstanttime();
	PrintStat(getinstanttime());
	fprintf(stdout, "Emulation Ends \n");

	total_emulation_time = temulation_end - temulation_start;
	fprintf(stdout,"Statistics: \n\n");
	fprintf(stdout,"\taverage packet inter arrival time = %.08g sec\n",avg_inter_arrival);
	fprintf(stdout,"\taverage packet service time = %.08g sec\n\n",avg_serv_time);
	fprintf(stdout,"\taverage number of packets in Q1 = %.08g\n",(double)avg_pkt_q1/total_emulation_time);
	fprintf(stdout,"\taverage number of packets in Q2 = %.08g\n",(double)avg_pkt_q2/total_emulation_time);
	fprintf(stdout,"\taverage number of packets at S = %.08g\n\n",(double)avg_pkt_s/total_emulation_time);
	fprintf(stdout,"\taverage time a packet spent in the system = %.08g sec\n",avg_pkt_sys_time);
	fprintf(stdout,"\tstandard deviation for time spent in system = %.08g sec \n\n",std_deviation);
	fprintf(stdout,"\ttoken drop probability = %.08g\n",token_drop_prob);
	fprintf(stdout,"\tpacket drop probability = %.08g\n",pkt_drop_prob);

	pthread_mutex_destroy(&my_mutex);
	pthread_cond_destroy(&queue2_cond);
	pthread_exit(NULL);


}
Beispiel #20
0
int main(int argc,char *argv[])

{

    FILE *fp;

    char line[2000];

    int num_mem;

    My402List list;

    memset(&list, 0, sizeof(My402List));

    (void)My402ListInit(&list); 
    

    if(argc==1)

    {

        printf("malformed command\n");

                exit(EXIT_FAILURE);

    }   



    if(argc==4)

    {

        printf("malformed command\n");

                exit(EXIT_FAILURE);

    }

    if(strlen(line)>1024)
    {
        printf("Length of line is more than 1024\n");
        exit(EXIT_FAILURE);

    }



    if(argc == 3 && (strncmp(argv[1],"sort",strlen(argv[1]))==0))

    {

    fp = fopen(argv[2], "r");

       

    if (fp==NULL)

    {

        fprintf(stderr, "Unable to open '%s'\n",argv[3]);

                exit(EXIT_FAILURE);

    }

    while (fgets(line,2000, fp)!=NULL)

    {
        //printf("%s\n",line);
        parse_line(line, &list);

    } 

     fclose(fp);

    }
    else if(argc == 2 && (strncmp(argv[1],"sort",strlen(argv[1]))==0))

    {

         fp =stdin;

    if (fp==NULL)

        {

        fprintf(stderr, "Unable to open '%s'\n",argv[3]);

                exit(EXIT_FAILURE);

        }

   

    while (fgets(line,2000, fp)!=NULL)

    {

      
         parse_line(line, &list);

               

    }
  fclose(fp);
}
    
else 
  {

    printf("Malformed Command");
    Usage();

  }  

    num_mem=My402ListLength(&list);

     BubbleSortForwardList(&list,num_mem);

   

    printlist(&list);

   

    return 0;

}       
void ParseFile(FILE *file){
  char buffer[1024];
  memset(buffer, 0, sizeof(buffer));
  
  transaction *obj = NULL;
  My402List list;
  memset(&list, 0, sizeof(My402List));
  (void)My402ListInit(&list);

  while(fgets(buffer, sizeof(buffer), file) != NULL){
    obj = (transaction*)malloc(sizeof(transaction));
    if(obj == NULL){
      fprintf(stderr, "%s\n", strerror(errno));
    }
    else{
      char *start_ptr = buffer;
      char *tab_ptr = strchr(start_ptr, '\t');
      
      int noofptr = 0;
      while(tab_ptr != NULL){
	noofptr++;
	tab_ptr++;
	start_ptr = tab_ptr;
	tab_ptr = strchr(start_ptr, '\t');
      }
      
      if(noofptr > 3){
	fprintf(stderr, "Too many tabs, Clearing memory and Quiting Program\n");
	free(obj);
	My402ListUnlinkAll(&list);
	exit(0);
      }

      if(noofptr < 3){
	fprintf(stderr, "Format Malformed, Clearing memory and Quiting Program\n");
	free(obj);
	My402ListUnlinkAll(&list);
	exit(0);
      }

      start_ptr = buffer;
      tab_ptr = strchr(start_ptr, '\t');

      if(Transaction_Type(obj, start_ptr, tab_ptr) == 0){
	fprintf(stderr, "Transaction Type failed, Clearing Memory and Quiting Program\n");
	free(obj);
	My402ListUnlinkAll(&list);
	exit(0);
      }
      tab_ptr++;
      start_ptr = tab_ptr;
      tab_ptr = strchr(start_ptr, '\t');
      
      if(Transaction_TimeStamp(obj, start_ptr, tab_ptr) == 0){
	fprintf(stderr, "Transaction Time failed, Clearing Memory and Quiting Program\n");
	free(obj);
	My402ListUnlinkAll(&list);
	exit(0);
      }

      tab_ptr++;
      start_ptr = tab_ptr;
      tab_ptr = strchr(start_ptr, '\t');
      
      if(Transaction_Amount(obj, start_ptr, tab_ptr) == 0){
	fprintf(stderr, "Transaction Amount failed, Clearing Memory and Quiting Program\n");
	free(obj);
	My402ListUnlinkAll(&list);
	exit(0);
      }

      tab_ptr++;
      start_ptr = tab_ptr;
      tab_ptr = strchr(start_ptr, '\n');

      Transaction_Description(obj, start_ptr, tab_ptr);
      

      //Now the struct is filled with the string fields read from the first line of the file
      if(My402ListLength(&list) == 0)
	(void)My402ListPrepend(&list, obj);
      else{
	My402ListElem *elem = NULL;
	for(elem = My402ListFirst(&list); elem != NULL; elem=My402ListNext(&list, elem)){
	  if((((transaction*)(elem->obj))->trans_time == obj->trans_time)){
	    fprintf(stderr, "Error - Two entry at same time, Quiting program\n");
	    free(obj);
	    My402ListUnlinkAll(&list);
	    exit(0);
	  }
	  if((((transaction*)(elem->obj))->trans_time > obj->trans_time)){
	    (void)My402ListInsertBefore(&list, obj, elem);
	    break;
	  }
	  if(My402ListNext(&list, elem) == NULL){
	    (void)My402ListAppend(&list, obj);
	    break;
	  }
	}
      }
    }
  }
  PrintTransactionList(&list);
  My402ListUnlinkAll(&list);
}
Beispiel #22
0
void DoSort(FILE *fp)
{
   /*
     Step1 a
     Open the file and generate linked list
   */
   trnx *t;
   char line[BUFFER];
   char *tokens;
   char *op,*timeval,*amt,*description;
   int errCheck = 1;
   /*
    Generate a list and Initialise it
   */
   My402List list;
   memset(&list,0,sizeof(My402List));

   (void)My402ListInit(&list);
   /*
   */
   fgets(line,BUFFER,fp);
   while (!feof(fp))
   {
     /*
       Perform the necessary error checks for the line
     */
     errCheck = errorCheckLine(line);

     if (errCheck == 0)
     {
       exit(0);
     }
     /*
       Extract each element in the file and store it
      each attribute of transaction.

     */
     t = malloc(sizeof(trnx));
     tokens = malloc(strlen(line));
     amt = malloc(strlen(line));
     strcpy(tokens,line);

     op = strtok(tokens,"\t");
     timeval = strtok(NULL,"\t");
     amt = strtok(NULL,"\t");
     description = strtok(NULL,"\t");
     /*
     Error Check for each of the tokens in the line
     */
     /*
        Operator
     */
     errCheck = 1;
     errCheck = errCheckOp(t,op);
     if (errCheck == 0)
     {
       fputs("Operator is invalid.Must be +/-\n",stderr);
       exit(0);
     }
     /*
        Time
     */
     errCheck = 1;
     errCheck = errCheckTime(&list,t,timeval);
     if (errCheck == 0)
     {
       fputs("Timestamp is invalid.\n",stderr);
       exit(0);
     }
     /*
        Amount
     */
     errCheck = 1;
     errCheck = errCheckAmount(t,amt);
     if (errCheck == 0)
     {
       fputs("Amount is invalid.\n",stderr);
       exit(0);
     }
     /*
       Description
     */
     errCheck = errCheckDesc(t,description);
     if (errCheck == 0)
     {
       exit(0);
     }
     /*
      Create node in the list
     */

     (void)My402ListAppend(&list,(void *)t);
     /*
       Get next element in the list
     */

     //free(tokens);
     //free(amt);
     fgets(line,BUFFER,fp);

   }
   fclose(fp);
   //PrintList(&list);
   BubbleSortList(&list,list.num_members);
   //PrintList(&list);
   DisplayOutput(&list);

}
Beispiel #23
0
int main(int argc, char *argv[]){

	My402SortElem *currentSortElem = NULL;	
	My402List list;
	My402ListInit(&list);
	My402List *pList = &list;	
	FILE *fp = stdin;
	char *fileName = {"\0"};
	char *pSortElem[4];
	pSortElem[0] = (char *)malloc(2*sizeof(char)); // 1 for +/- and the other for '\0'	
	pSortElem[1] = (char *)malloc(11*sizeof(char));//MAX 10, +1 for terminating char
	pSortElem[2] = (char *)malloc(sizeof(int));
	pSortElem[3] = (char *)malloc(sizeof(1024));
	
	//TODO: output to stdout and error to stderr
		
	//FIXME: re-check the initialization part	
	
	char buf[CHAR_LIMIT+26] = {'\0'}; 	
	My402SortElem *current = NULL;
	char *start_ptr = buf;
	char *tab_ptr = NULL;
	int isMalFormed = FALSE;
	int tabNumber = 0;
	char *str = (char *)malloc(sizeof(1050));
	memset(str,sizeof(str),'\0');
	char transType='\0';
	char transTime[10] = {'\0'};
	char transAmount[10] = {'\0'};	
	char *transDesc = (char *)malloc(sizeof(1024));	
	memset(transDesc, sizeof(transDesc), '\0');

	//FIXME: user should be ketp asking or program should exit?
	//FIXME: modify according to the makefile	
		
	if(!(argc == 2 || argc == 1)){
		fprintf(stderr, "\nError::Too many or too few arguments.");
		fprintf(stderr, "\nPlease enter the command in either of the following formats:\n");
		fprintf(stderr, "\n\tmake sort tfile");
		fprintf(stderr, "\n\tor");
		fprintf(stderr, "\n\tmake sort\n\n");	
		return 0;
	}
	//FIXME: when working with make file	
	if(argc == 2){
		fileName = argv[1];		
		fp = fopen(fileName,"r");
	}
	if(fp == NULL){
		//FIXME: Is there a case for unable to open stdin? 
		fprintf(stderr, "\nUnable to open the file: %s. Please check the given file name and its path and try again!\n", argv[2]);					return 0;	
	}

	while((str = fgets(buf, sizeof(buf), fp)) != NULL){
			printf("\n complete string length:%d\n", strlen(str));	
			if(strlen(str)>CHAR_LIMIT+1){ //+1 for new line char
				fprintf(stderr, "\n1.The line has more than %d characters, so the program aborts now! \n", CHAR_LIMIT);	
				return 0;
			}else{
			//Parse and see if it is malformed	
				//printf("\nStruct starts\n");	
				
				start_ptr = str;	
				for(tabNumber=0; tabNumber<3; tabNumber++){
					tab_ptr = strchr(start_ptr,'\t');
					if(tab_ptr == NULL){
						fprintf(stderr, "\n2.The string is malformed, so the program aborts now! \n");	
						return 0;
					}
					if(tab_ptr != NULL){
						*tab_ptr = '\0';	
					}		
					//FIXME: substrings must not be NULL
					//printf("%s ",substring(buf,start_ptr));
					pSortElem[tabNumber] = substring(buf, start_ptr);
					start_ptr = tab_ptr+1;	
				}
				transDesc = substring(buf, start_ptr);
				if(transDesc == ""){
				
					fprintf(stderr, "\n3.The string is malformed, so the program aborts now! \n");	
					return 0;
				}	
				//printf("%s", substring(buf,start_ptr));
				pSortElem[3] = substring(buf, start_ptr);	
				//FIXME: verify each field has the right data
				if(verifySortElem(pSortElem) == FALSE){
					fprintf(stderr, "\n4.The string is malformed, so the program aborts now! \n");	
					return 0;
				}	
				currentSortElem = createSortElem(pSortElem);	
				insertionSort(pList, currentSortElem);
				/*
				if(strchr(str,'\n') == NULL){
					break; //EOF reached	
				}*/
			}	
		
		//}else{
			//printf("\nThe last character: %c", str[strlen(str)-1]=='\n'?'t':'f');	
			//printf("\n strlen(buf)=%d", (int)strlen(buf));	
			//printf("\nThe line has more than %d characters, so the program aborts now! \n", CHAR_LIMIT);	
			//return 0;
		//}
	}
	printf("\n hit the EOF..came out\n");	
	fclose(fp);	
	printList(pList);
	return 0;
}
Beispiel #24
0
main( int argc, char *argv[] )
{
      int status;
      char tt;
      unsigned int ti;
      float ff;
      char amt[10];
      char des[100];
      int number = 1024;
      char line[1026];
      My402List *list =(My402List *)malloc(sizeof(My402List));
      printf("start");
      FILE * fp;
      if( argc == 1)
      { 
		fp = stdin;
        if(ferror (fp))
		{
            printf("error opening file!");
            clearerr(fp);
            exit(0);
		} 
      }
      else
	  {
		fp = fopen( "gg.txt" , "r" );
		if(ferror (fp))
		{
            printf("error opening file!");
            clearerr(fp);
            exit(0);
		} 
		else
		{                              
			My402ListElem *elem = (My402ListElem *)malloc(sizeof(My402ListElem));
			status = My402ListInit(list);
			if(status != FALSE)
			{
				while( fgets(line,number,fp) != NULL)
				{         
					sscanf(line,"%c\t%d\t%s\t%[^\n]s",&tt,&ti,amt,des);
					printf("%c\n%d\n%s\n%s\n",tt,ti,amt,des);
					Mytransaction * tr =(Mytransaction*)malloc(sizeof(Mytransaction));
					tr->transtype = tt;
					tr->time      = ti;
					strcpy( tr->amounts , amt );
					strcpy( tr->desc , des );      
					status = Mychecker(list,tr);
					if(status == TRUE)
					{
						status = My402ListPrepend(list,tr);
						if(status != TRUE )
						printf("not prepended");
					}
				} 
            }
            else
            {
                printf("list not initialised");
            }              
		}	
      
      BubbleSortForwardList(list,My402ListLength(list));
      //***output********* 
      printf("\n00000000011111111112222222222333333333344444444445555555555666666666677777777778");
      printf("\n12345678901234567890123456789012345678901234567890123456789012345678901234567890");
      printf("\n+-----------------+--------------------------+----------------+----------------+");
      printf("\n|       Date      | Description              |         Amount |        Balance |");
      printf("\n+-----------------+--------------------------+----------------+----------------+");
      MyListTraverse(list);  
      printf("\n+-----------------+--------------------------+----------------+----------------+");  
      }
}