Ejemplo n.º 1
0
int main(int argc, const char *argv[])
{
    print_nums(n, 10);
    moveZeroes(n, 10);
    print_nums(n, 10);
    return 0;
}
Ejemplo n.º 2
0
void bubble_sort(int nums[], int len)
{
    printf("Before Bubble Sort:\n");
    print_nums(nums, len);
    int i,j;
    int tmp = 0;
    int exchange = 0;
    int second = 0;
    int flag = 0;
    for (i = 0; i < len; i++) {
        exchange = 0;
        if (flag > i) {
            second = flag;
        } else {
            second = i;
        }
        for (j = len - 1; j > second; j--) {
            if (nums[j] < nums[j - 1]) {
                exchange = 1;
                flag = j;
                tmp = nums[j];
                nums[j] = nums[j - 1];
                nums[j - 1] = tmp;
            }
        }
        if (exchange == 0) {
            break;
        }
    }
    printf("After Bubble Sort:\n");
    print_nums(nums, len);
}
Ejemplo n.º 3
0
int main()
{
    int a[] = {7, 12, -2, 0, 3, 30, 20, 19};
    printf("Before quick sort:\n");
    print_nums(a, sizeof(a)/4);
    quick_sort(a, 0, sizeof(a)/4 - 1);
    printf("After quick sort:\n");
    print_nums(a, sizeof(a)/4);
    return 0;
}
Ejemplo n.º 4
0
static void rt_print(const void *ip, const struct xt_entry_match *match,
                     int numeric)
{
    const struct ip6t_rt *rtinfo = (struct ip6t_rt *)match->data;

    printf("rt ");
    if (rtinfo->flags & IP6T_RT_TYP)
        printf("type:%s%d ", rtinfo->invflags & IP6T_RT_INV_TYP ? "!" : "",
               rtinfo->rt_type);
    print_nums("segsleft", rtinfo->segsleft[0], rtinfo->segsleft[1],
               rtinfo->invflags & IP6T_RT_INV_SGS);
    if (rtinfo->flags & IP6T_RT_LEN) {
        printf("length");
        printf(":%s", rtinfo->invflags & IP6T_RT_INV_LEN ? "!" : "");
        printf("%u", rtinfo->hdrlen);
        printf(" ");
    }
    if (rtinfo->flags & IP6T_RT_RES) printf("reserved ");
    if (rtinfo->flags & IP6T_RT_FST) printf("0-addrs ");
    print_addresses(rtinfo->addrnr, (struct in6_addr *)rtinfo->addrs);
    if (rtinfo->flags & IP6T_RT_FST_NSTRICT) printf("0-not-strict ");
    if (rtinfo->invflags & ~IP6T_RT_INV_MASK)
        printf("Unknown invflags: 0x%X ",
               rtinfo->invflags & ~IP6T_RT_INV_MASK);
}
Ejemplo n.º 5
0
int main(void) {
  var = -42;

  breakpoint();

  atomic_printf("var is %d\n", var);
  test_assert(var == -42);

  make_stack_executable();

  breakpoint();

  atomic_puts("EXIT-SUCCESS");
  return 0;

  /* not reached */
  mutate_var();
  print_nums();
  alloc_and_print();
  make_unhandled_syscall();
  print_time();
}
Ejemplo n.º 6
0
void play_sound(short which, short how_many_times) { // if < 0, play asynch
#if defined(__APPLE__)
	Handle sndhandle;
	unsigned long dummy;
	OSErr err;
	SndCommand theCommand;
	if (!play_sounds || how_many_times == 0) return;
	
	if (abs(which) > NUM_SOUNDS) {
		//char msg[50];
		/*s*/printf(/*msg,*/"Error: Sound #%i does not exist.\n",abs(which));
		//give_error(msg,"",0);
		return;
	}
	
	channel++;
	
	if (channel > numchannel) channel = 0;
	
	if (!sound_going(abs(which)) && load_when_play[abs(which)]) 
		sndhandle = GetResource('snd ',20000 + abs(which));
	else sndhandle = sound_handles[abs(which)];
	
	if (which > 0)
 		if (always_asynch[which])
			which *= -1;
	
 	if (sndhandle != NULL)
	{
		HLock(sndhandle);
		
		if (which < 0) err = SndPlay(chan[channel],(SndListHandle) sndhandle,true); // Normal SndPlay
		else {
			err = SndPlay(chan[channel],(SndListHandle) sndhandle,false);
		}
		if (err != 0) {
			printf("Sound error.\n");
			//add_string_to_buf("Sound Error. Error codes:");
			//print_nums(channel,which,err);
			//add_string_to_buf("Your system could not play a sound.");
			//add_string_to_buf("Make sure editor isn't running.");
			//add_string_to_buf("Turn off sounds if necessary.");
		}
		HUnlock(sndhandle);
		snd_played[channel] = abs(which);
		theCommand.cmd = callBackCmd;
		theCommand.param1 = 0;
#ifndef EXILE_BIG_GUNS
		theCommand.param2 = SetCurrentA5();
#endif
#ifdef EXILE_BIG_GUNS
		theCommand.param2 = 0;
#endif
		SndDoCommand(chan[channel],&theCommand,true);
	}
	else SysBeep(20);
	if (which < 0)
		Delay(sound_delay[-1 * which],&dummy);
	if(how_many_times > 1)
		play_sound(which, how_many_times - 1);
#elif defined(WIN32)
	short i,num_fails = 0;
	char snd_name[30];
	bool asyn = false,a_sound_did_get_played = false;
	bool not_asyn = false,check_sound;
	HRSRC h;
	if ((sounds_missing) || (!play_sounds) || (how_many_times == 0))
		return;
	
	if (which < 0) {
		asyn = true;
		which = which * -1;
		}
	if (which >= 1000) {
		which -= 1000;
		not_asyn = true;
		}

	if (which >= 100)
		return;

	if ((always_asynch[which] == true) &&
	((can_ignore[which] == 1) || (can_ignore[which] >= 3)))
		asyn = true;
	if ((can_ignore[which] > 0) && (can_ignore[which] < 5) && (party.stuff_done[305][5] == 1))
		return;
	if ((can_ignore[which] != 1) && (can_ignore[which] < 3))
		asyn = false;
	if ((party.stuff_done[305][5] == 1) && (can_ignore[which] < 5))
		asyn = false;
	if (not_asyn == true)
		asyn = false;

	if ((load_when_play[which] == true) && (sound_handles[which] == NULL)) {
			asyn = false;
		sprintf((char *)snd_name,"#%d",which + 1);
		h = FindResource(hModule,snd_name,"#100");

		sound_handles[which] = LoadResource(hModule,h);
		snds[which] = (char *) LockResource(sound_handles[which]);

		}

	if (store_last_sound_played == 6)
		sndPlaySound(NULL,0);

	if (asyn == true) {
		if (can_ignore[which] >= 4)
			check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP);
			else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY);

		while (check_sound == false) {

			if (can_ignore[store_last_sound_played] == 4) {// then sound goes away
				return;
				}


			num_fails++;
			if (num_fails < 40)
				sound_pause(25);
				else {
					MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error a. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.",
					  "Sound Error",MB_OK | MB_ICONEXCLAMATION);
					print_nums(111,which,num_fails);
					sounds_fucked = true;
					return;
					}
			sndPlaySound(NULL,0);

			if (can_ignore[which] >= 4)
				check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP);
				else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY);
			}
	  a_sound_did_get_played = true;
	  }
		else {
		if (can_ignore[which] >= 4)
			check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP);
			else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY);
		while (check_sound == false) {
			if (can_ignore[store_last_sound_played] == 4) {// then sound goes away
				return;
				}


			num_fails++;
			if (num_fails < 40)
				sound_pause(25);
				else {
					MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error b. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.",
					 "Sound Error",MB_OK | MB_ICONEXCLAMATION);
					print_nums(222,which,num_fails);
					sounds_fucked = true;
					return;
					}
			sndPlaySound(NULL,0);

			if (can_ignore[which] >= 4)
				check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP);
				else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY);
			}
		a_sound_did_get_played = true;
	  }

	store_last_sound_played = which;

	if ((load_when_play[which] == true) && (asyn == false)) 
		sound_handles[which] = NULL;
		
	for (i = 0; i < NUM_SOUNDS; i++)
		if ((load_when_play[which] == true) && (sound_handles[which] != NULL)
			&& (a_sound_did_get_played == true) && (i != which))
		{
			sound_handles[i] = NULL;
		}
#endif
}