Skip to content

Instantly share code, notes, and snippets.

@19h
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 19h/15a3b9aafa5c71cd6a88 to your computer and use it in GitHub Desktop.
Save 19h/15a3b9aafa5c71cd6a88 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct {
bool isRoot;
} selectedViewModel;
void log (const char *type) {
write(0, type, strlen(type));
}
int viewModelStates[] = {
0, 0, 0, 1, 1
};
int viewModelAmount = sizeof(viewModelStates) / sizeof(viewModelStates[0]);
int main() {
char type[] = "mixed";
selectedViewModel* selectedViewModels = malloc(viewModelAmount * sizeof *selectedViewModels);
int i;
for (i = 0; i < viewModelAmount; ++i) {
selectedViewModels[i].isRoot = viewModelStates[i];
}
if (viewModelAmount < 2) {
if (selectedViewModels[0].isRoot) {
strncpy(type, "root", 5);
} else {
strncpy(type, "child", 6);
}
} else {
bool isRoot = selectedViewModels[0].isRoot;
char i;
for (i = 1; i < viewModelAmount; ++i) {
if (selectedViewModels[i].isRoot != isRoot) {
break;
}
if (i == viewModelAmount - 1) {
if (isRoot) {
strncpy(type, "root", 5);
} else {
strncpy(type, "child", 6);
}
}
}
}
log(type);
free(selectedViewModels);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment