Beispiel #1
0
/* 
 * reads in form:
 *      \ *[matching]\ *=[0-9]^\n
 *   
 * MUST be queried in order, or given a new filedescriptor for each call
 */
int config_read(FILE* descriptor, char* matching, int* saveto) {
    char c, s=0, *old = matching;
    // clear the leading spaces
    while( (c=fgetc(descriptor)) == ' ');

    while(*matching == c) {
        c = fgetc(descriptor);
        s = *(++matching)==0;
    }

    if (!s) {
        //read to end of line
        while( (c=fgetc(descriptor)) != '\n');
        return config_read(descriptor, old, saveto);
    }

    //read up to the = sign
    while( (c=fgetc(descriptor)) == ' ');
    while( (c=fgetc(descriptor)) == ' ');

    int r = build_int(0, c);
    while( (c = fgetc(descriptor)) != ' ' && c != '\n' && c != 0) {
        r = build_int(r, c);
    }
    while( (c=fgetc(descriptor)) != '\n');

    *saveto = r;
    return 1;
}
Beispiel #2
0
void clear_sound(void) {
	char *active_sound_ptr = sound_addr;
	int size = build_int(active_sound_size);
	int i;
	for (i=0;i<size;i++) {
		*active_sound_ptr = 0;
		active_sound_ptr++;
	}
}
Beispiel #3
0
int reverse(int x) {
    std::vector<int> digits;   // initialize without knowing size

    while(x != 0){
        digits.push_back(x - (x / 10) * 10);
        x = x / 10;
    }

    return build_int(digits);
}
Beispiel #4
0
int main()
{
	list *newptr=NULL;
	list *headptr=NULL;
	list *tailptr=NULL;
	int choice1,choice2;
	char enter;
	char my_char;
	short my_short;
	int my_int;
	long my_long;
	float my_float;
	double my_double;
	printf("Which action you want to do? 1.enqueue 2.dequeue 3.exit\n");
    	scanf("%d",&choice1);
    	while(choice1>3||choice1<1)
    	{
        	printf("Out of range!Please input again\n");
        	scanf("%d",&choice1);
    	}
	while(choice1!=3)
	{
		if(choice1==1)
		{
			printf("Please choose a type then input a data to push:0.char 1.short 2.int 3.long 4.float 5.double\n");
			printf("or ptr to 6.char 7.short 8.int 9.long 10.float 11.double\n");
			scanf("%d",&choice2);
			while(choice2<0||choice2>11)
			{
				printf("Out of range!Please input type again\n");
				scanf("%d",&choice2);
			}
			if(choice2==0)
			{
				printf("Then input a word\n");
				scanf("%c %c",&enter,&my_char);
				build_char(&newptr,choice2,my_char);
				enqueue_char(&headptr,&tailptr,&newptr);
			}
			if(choice2==1)
			{
				printf("Then input data\n");
				scanf("%hd",&my_short);
				build_short(&newptr,choice2,my_short);
				enqueue_short(&headptr,&tailptr,&newptr);
			}
			if(choice2==2)
			{
				printf("Then input data\n");
				scanf("%d",&my_int);
				build_int(&newptr,choice2,my_int);
				enqueue_int(&headptr,&tailptr,&newptr);
			}
			if(choice2==3)
			{
				printf("Then input data\n");
				scanf("%ld",&my_long);
				build_long(&newptr,choice2,my_long);
				enqueue_long(&headptr,&tailptr,&newptr);
			}
			if(choice2==4)
			{
				printf("Then input data\n");
				scanf("%f",&my_float);
				build_float(&newptr,choice2,my_float);
				enqueue_float(&headptr,&tailptr,&newptr);
			}
			if(choice2==5)
			{
				printf("Then input data\n");
				scanf("%lf",&my_double);
				build_double(&newptr,choice2,my_double);
				enqueue_double(&headptr,&tailptr,&newptr);
			}
			if(choice2==6)
			{
				printf("Then input a word\n");
				scanf("%c %c",&enter,&my_char);
				build_ptr_char(&newptr,choice2,my_char);
				enqueue_ptr_char(&headptr,&tailptr,&newptr);
			}
			if(choice2==7)
			{
				printf("Then input data\n");
				scanf("%hd",&my_short);
				build_ptr_short(&newptr,choice2,my_short);
				enqueue_ptr_short(&headptr,&tailptr,&newptr);
			}
			if(choice2==8)
			{
				printf("Then input data\n");
				scanf("%d",&my_int);
				build_ptr_int(&newptr,choice2,my_int);
				enqueue_ptr_int(&headptr,&tailptr,&newptr);
			}
			if(choice2==9)
			{
				printf("Then input data\n");
				scanf("%ld",&my_long);
				build_ptr_long(&newptr,choice2,my_long);
				enqueue_ptr_long(&headptr,&tailptr,&newptr);
			}
			if(choice2==10)
			{
				printf("Then input data\n");
				scanf("%f",&my_float);
				build_ptr_float(&newptr,choice2,my_float);
				enqueue_ptr_float(&headptr,&tailptr,&newptr);
			}
			if(choice2==11)
			{
				printf("Then input data\n");
				scanf("%lf",&my_double);
				build_ptr_double(&newptr,choice2,my_double);
				enqueue_ptr_double(&headptr,&tailptr,&newptr);
			}
		}
		if(choice1==2)
		{
			dequeue(&headptr,&tailptr);	
		}
		printf("Which action you want to do? 1.enqueue 2.dequeue 3.exit\n");
       		scanf("%d",&choice1); 
        	while(choice1>3||choice1<1)
        	{
            		printf("Out of range!Please input again\n");
            		scanf("%d",&choice1);
        	} 
	}
	return 0;
}
Beispiel #5
0
status* read_mouse_std(FILE* desc) {
    char lineID = fgetc(desc);
    while( (lineID=fgetc(desc)) == ' ' );

    if (lineID == 't') {
        // this is a title line, ignore it
        while( (lineID=fgetc(desc)) != '\n' );
        return NULL;
    }

    status* cur = malloc(sizeof(status));

    cur -> reading_time = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> reading_time
            = build_int(cur -> reading_time, lineID);
    }
    while( (lineID=fgetc(desc)) == ' ' );

    cur -> contact_xpos = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> contact_xpos
            = build_int(cur -> contact_xpos, lineID);
    }
    while( (lineID=fgetc(desc)) == ' ' );

    cur -> contact_ypos = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> contact_ypos
            = build_int(cur -> contact_ypos, lineID);
    }
    while( (lineID=fgetc(desc)) == ' ' );

    cur -> contact_preassure = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> contact_preassure
            = build_int(cur -> contact_preassure, lineID);
    }
    while( (lineID=fgetc(desc)) == ' ' );

    cur -> contact_points = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> contact_points
            = build_int(cur -> contact_points, lineID);
    }
    while( (lineID=fgetc(desc)) == ' ' );

    cur -> contact_size = build_int(0, lineID);
    while( (lineID=fgetc(desc)) != ' ' ) {
        cur -> contact_size
            = build_int(cur -> contact_size, lineID);
    }
    while( (lineID=fgetc(desc)) != '\n' );

    return cur;
}