Example #1
0
/**
 *  @brief The main manager function. Gets a line of input and prints the output.
 */
int main()
{
	char output[MAX_INPUT_LENGTH], input[MAX_INPUT_LENGTH]; // input saves the original input.
	int currentChar, i = 0;

	// Get input from user.
	while ((i < MAX_INPUT_LENGTH) && ((currentChar = getchar()) != NEW_LINE))
	{
		input[i] = currentChar;
		// Changes input if needed
		currentChar = changeLetterCase(currentChar);
		currentChar = changeNumber(currentChar);
		output[i] = currentChar;
		i++;
	}
	
	// Fill remaining cells with null values to avoid weird chars.
	for (; i < MAX_INPUT_LENGTH; i++)
	{
		input[i] = ASCII_NULL;
		output[i] = ASCII_NULL;
	}

	printf("\"%s\" -> \"%s\"\n", &input, &output);
	return 0;
}
void BaseAnnotationHighlighter::highlightBlock(const QString &text)
{
    if (text.isEmpty() || d->m_changeNumberMap.empty())
        return;
    const QString change = changeNumber(text);
    const ChangeNumberFormatMap::const_iterator it = d->m_changeNumberMap.constFind(change);
    if (it != d->m_changeNumberMap.constEnd())
        setFormat(0, text.length(), it.value());
}
Example #3
0
File: main.c Project: YanShby/C-
int main(int argc, const char * argv[]) {
    // insert code here...
    printf("Hello, World!\n");
    int x;
    scanf("%d",&x);
    printf("NumberOf1_1(x):%d\nNumberOf1_2(x):%d\nNumberOf1_3(x):%d\n",NumberOf1_1(x),NumberOf1_2(x),NumberOf1_3(x));
    printf("%d\n",isTwo(x));
    printf("%d\n",changeNumber(10, 13));
    return 0;
}
Example #4
0
void ofApp::keyPressed(int key) {
    switch (key) {
        case '0':
            changeNumber(10);
            break;
        case '1':
            changeNumber(1);
            break;
        case '2':
            changeNumber(2);
            break;
        case '3':
            changeNumber(3);
            break;
        case '4':
            changeNumber(4);
            break;
        case '5':
            changeNumber(5);
            break;
        case '6':
            changeNumber(6);
            break;
        case '7':
            changeNumber(7);
            break;
        case '8':
            changeNumber(8);
            break;
        case '9':
            changeNumber(9);
            break;
            
        default:
            break;
    }
}
Example #5
0
int main(int argc, char const *argv[]) {
    if (argc == 1) {
        printf("ERROR: the program takes one argument\n");
        return 0;
    }
    argv[1];
    FILE *input = fopen(argv[1], "r");
    Book *book = createBook();
    readBookFromFile(input, book);
    fclose(input);

    sh_fileName = argv[1];
    sh_book = book;
    signal(SIGINT, signal_handler); 

    char command[10];
    char *name = NULL;   //(char *) malloc(sizeof(char)*80);
    char *number = NULL; // (char *) malloc(sizeof(char)*80);
    char *str = NULL;    //(char *) malloc(80);

    bool corName;
    bool corNumber;
    
    while (true) {
        corName = true;
        corNumber = true;
        scanf("%s", command);
        if(!strcmp(command, "debprint")) {
            fullPrint(book);
        } else if(!strcmp(command, "print")) {
            printBook(stdout, book);
        } else if(!strcmp(command, "find")) {
            str = read(stdin);
            printFound(stdout, book, str);
            free(str);
        } else if(!strcmp(command, "create")) {
            name = read(stdin); number = read(stdin);
            corName = correctName(name);
            corNumber = correctNumber(number);
            if (correctName && correctNumber) {
                appendBook(book, name, number);
            }
            free(name); free(number);
        } else if(!strcmp(command, "delete")) {
            int id;
            scanf("%d", &id);
            removeContact(book, id);
        } else if(!strcmp(command, "change")) {
            int id;
            scanf("%d%s", &id, command);
            str = read(stdin);
            if(!strcmp(command, "number")) {
                corName = correctName(str);
                if (corName)
                    changeNumber(book, id, str);
            } else if (!strcmp(command, "name")) {
                corNumber = correctNumber(str);
                if (corNumber)
                    changeName(book, id, str);
            } else {
                printf("ERROR: Expected \"name\" or \"number\" after id in the command change\n");
            }
            free(str);
        } else if(!strcmp(command, "exit")) {
            FILE* output = fopen(argv[1], "w");
            printBook(output, book);
            fclose(output);
            deleteBook(book);
            break;
        } else {
            printf("ERROR: Unknown command %s\n", command);
        }
        if (!corName) {
            printf("ERROR: Invalid name\n");
        }
        if (!corNumber) {
            printf("ERROR: Invalid number\n");
        }
    }

    return 0;
}
Example #6
0
// Run a state machine testing for inputs, which plays
// a simple song as we go.
void configure(void)
{
	CONFIGURE state;
	//static uint16 scrollcredits;		// How far to scroll the credits
	//const char* credits = "Edwin Amsler 2010 to 2012   Edwin Amsler 2010 to 2012";

	Controller control;
	unsigned int oldControl	= 0;
	uint8 changed	= 0;	// If we need to redraw the screen or update the eeprom
	DELTA settingDelta 		= NONE;	// How much to change the current setting

	put(VFD_CLR);
	put(VFD_FF);
	println("Config Mode:");
	print("Use directional pad");

	state = INIT;

	for(;;)
	{
		playNote();
		control = readController();

		// Prevents key repeat when the user holds the button down
		buttonDelta(&control.buttons, &oldControl);

		// Increment decrement setting
		settingDelta = NONE;

		// Handle button presses
		switch (control.buttons)
		{
			case PS_SELECT:	// Escape config mode
				put(VFD_CLR);
				put(VFD_FF);

				// Don't save if nothing changed
				if (0 == (changed & UPDATE_EEPROM))
					return;

				print("Saving settings...");

				if (volume != eeprom_read_byte((uint8_t*)VOLUME))
					eeprom_write_byte((uint8_t*)VOLUME, volume);

				if (brightness != eeprom_read_byte((uint8_t*)BRIGHTNESS))
					eeprom_write_byte((uint8_t*)BRIGHTNESS, brightness);

				if (attack != eeprom_read_byte((uint8_t*)ATTACK))
					eeprom_write_byte((uint8_t*)ATTACK, attack);

				if (decay != eeprom_read_byte((uint8_t*)DECAY))
					eeprom_write_byte((uint8_t*)DECAY, decay);

				if (sustain != eeprom_read_byte((uint8_t*)SUSTAIN))
					eeprom_write_byte((uint8_t*)SUSTAIN, sustain);

				if (release != eeprom_read_byte((uint8_t*)RELEASE))
					eeprom_write_byte((uint8_t*)RELEASE, release);

				if (waveform != eeprom_read_byte((uint8_t*)WAVEFORM))
					eeprom_write_byte((uint8_t*)WAVEFORM, waveform);

				// Mark that we saved data. EEPROM inits to 0xFF on programming
				eeprom_write_byte(INIT, 0);

				put(VFD_CLR);
				put(VFD_FF);
				return;

			case PS_UP:		// Go to previous config option
				state--;
				changed |= UPDATE_SCREEN;
				break;

			case PS_DOWN:	// Go to next config option
				state++;
				changed |= UPDATE_SCREEN;
				break;

			case PS_LEFT:
				settingDelta = DECREMENT;
				changed |= UPDATE_EEPROM;
				break;

			case PS_RIGHT:
				settingDelta = INCREMENT;
				changed |= UPDATE_EEPROM;
				break;

			default:		// If no buttons press, go back to
				continue;	// the top of the loop
		}

		// So we don't navigate to nowhere.
		// As confusing as it is, WAVEFORM is just
		// the last configuration option. When adding
		// new options, change this. Should have used
		// a sentry value
		state %= (uint8)WAVEFORM + 1;

		// Draw our menu
		switch (state)
		{
			case VOLUME:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Volume:          <->");
					changed &= ~UPDATE_SCREEN;
				}
				volume = changeNumber(volume, 15, &settingDelta);
				SIDSet(MODE_VOL, volume & 0x0F);
				break;

			case BRIGHTNESS:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Brightness:      <->");
					changed &= ~UPDATE_SCREEN;
				}
				brightness = changeNumber(brightness, 3, &settingDelta);
				put(VFD_ESC);
				put(VFDA_LUM);
				put(brightness * 64);	// The hell? *64? Oh! 255/4=64. The Noritake
										// VFD uses 0 to 255 for brightness.
				break;

			case ATTACK:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Note Attack:     <->");
					changed &= ~UPDATE_SCREEN;
				}
				
				// There's something critically wrong here (and in other cases below).
				// Since we don't factor in the other half of the byte, setting this nibble
				// is knocking the decay out of the picture. What needs to happen, is it needs
				// to OR the decay nibble before setting the SID's register.
				
				// Since the SID is mostly read-only, it's the only way to do it.
				attack = changeNumber(attack, 15, &settingDelta);
				//SIDSet(ATK_DECAY, attack << 4);
				
				// EX: (Need to verify this works)
				SIDSet(ATK_DECAY, (attack << 4) | (decay & 0x0f));
				
				break;

			case DECAY:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Note Decay:      <->");
					changed &= ~UPDATE_SCREEN;
				}
				decay = changeNumber(decay, 15, &settingDelta);
				SIDSet(ATK_DECAY, (attack << 4) | (decay & 0x0F));
				break;

			case SUSTAIN:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Note Sustain:    <->");
					changed &= ~UPDATE_SCREEN;
				}
				sustain = changeNumber(sustain, 15, &settingDelta);
				SIDSet(STN_RLS, (sustain << 4) | (release & 0x0F));
				break;

			case RELEASE:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Note Release:    <->");
					changed &= ~UPDATE_SCREEN;
				}
				release = changeNumber(release, 15, &settingDelta);
				SIDSet(STN_RLS, (sustain << 4) | (release & 0x0F));
				break;

			case WAVEFORM:
				if (changed)
				{
					put(VFD_CLR);
					put(VFD_FF);
					print("Waveform Type:   <->");
					changed &= ~UPDATE_SCREEN;
				}
				waveform = changeEnum(waveformEnum, waveform, 3, &settingDelta);
				controlRegister &= 0xF0;
				controlRegister |= 1 << (4 + waveform);
				SIDSet(CONTROL, controlRegister);
				break;

			default:
				put(VFD_CLR);
				put(VFD_FF);
				print("    PlaySynth 64    ");

				// I broke the credits :(

				break;
		}

		// TODO: Another switch statement for setting registers (remove code dupe)
		// TODO: Store text headers in an array that's indexed by state (remove yet more code dupe)
	}
}