/* * typewriter.c * * Computer Science 50, Fall 2011 * section6 * * Credit: Matthew Chartier * * Practice with structs. */ #include #include #include int main(void) { // open a new document FILE *fp = fopen("doc.txt", "w"); // check for successful open if (fp == NULL) { printf("Could not open file.\n"); return 1; } // store each line of text string input; // get text from user and save to file while(true) { // get text from user printf("\nEnter a new line of text (or \"quit\"):\n"); input = GetString(); // if user wants to quit if (strcmp(input, "quit") == 0) { // close the file fclose(fp); return 0; } // if user wants to enter text else { fputs(input, fp); fputs("\n", fp); printf("\nCHA-CHING!\n"); } } }