int main(int argc, char **argv)
{
 int length, upperBound;
 printf("please type the number of dimensions you need for the randomised array:\n");
 scanf("%i", &length);
 printf("please name an integer of the random scale:\n");
 scanf("%i", &upperBound);
 int rdmArray[length];
 
 randomizeArray(rdmArray, length, upperBound);
 printArray(rdmArray, length);
 return 0; 
}
示例#2
0
void main(void) {
    int array[ARRAY_SIZE];

    findEvensInArray(randomizeArray(array));
}
示例#3
0
//Creates the random music array (fist time through) and retrieves the
// filepath of the next music file to play.
void get_random_file(char *filetype, char *path)
{
	DIR_ITER *dir = NULL;
	char filename[1024];
	int cnt = 0;
	int next = 0;
	struct stat filestat;
	
	if (fileCount==0 && !first_time) goto out;
	
	dbg_printf(gt("Music: Looking for %s files in: %s"), filetype, path);
		dbg_printf("\n");

	// Open directory
	//snprintf(dirname, sizeof(dirname), "%s", path);
	dir = diropen(path);
	if (!dir) return;

	if (first_time) {
		while (!dirnext(dir, filename, &filestat)) {
			// Ignore invalid entries
			if (match_ext(filename, filetype) && !(filestat.st_mode & S_IFDIR))
				fileCount++;
		}
		dbg_printf(gt("Music: Number of %s files found: %i"), filetype, fileCount);
		dbg_printf("\n");

		first_time = false;
		//if no files found then no need to continue
		if (fileCount==0) goto out;
		
		//allocate the random music array
		musicArray = realloc(musicArray, fileCount * sizeof(int));
		if (!musicArray) {
			fileCount = 0;
			goto out;
		}
		initializeArray(musicArray, fileCount);
		randomizeArray(musicArray, fileCount);

		//check array contents
		int i;
		dbg_printf(gt("Music: musicArray contents: "));
		for (i=0; i<fileCount; i++)
			dbg_printf("%i ", musicArray[i]);
		dbg_printf("\n");

		//reset the directory
		dirreset(dir);
	}

	if (fileCount > 0) {
		//get the next file index
		lastPlayed++;
		if (lastPlayed > fileCount-1) lastPlayed = 0;
		next = musicArray[lastPlayed];
		dbg_printf(gt("Music: Next file index to play: %i"), next);
		dbg_printf("\n");
		
		//iterate through and find our file
		while (!dirnext(dir, filename, &filestat)) {
			if (match_ext(filename, filetype) && !(filestat.st_mode & S_IFDIR)) {
				cnt++;
				if (cnt==next) {
					//save path
					snprintf(music_fname, sizeof(music_fname), "%s/%s", path, filename);
					goto out;
				}
			}
		}
	}

	out:;
	//close the directory
	dirclose(dir);	 
}