Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MYSTERY PROGRAM
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- void FlushInput(void);
- bool function1(char*);
- bool function2(char*, char*);
- int main(void){
- FILE* fIn = NULL;
- char textIn[300];
- char fN[80];
- char sv = 'y';
- bool result = false;
- printf("Enter in some input:");
- if(fgets(textIn,300,stdin)){
- printf("Your entered in %d characters.\n", (int) strlen(textIn));
- printf("Enter in some more input: "); //Put main.c as input here on Replit.... if you dare :)
- fscanf(stdin,"%s",fN);
- if(function1(fN) == true){
- printf("Continue? Press 'y' to continue:");
- FlushInput();
- scanf("%c", &sv);
- if(sv == 'y')
- result = function2(textIn, fN);
- else
- printf("You chose not to continue.\n");
- }
- else{
- result = function2(textIn, fN);
- }//end if-else
- }
- else {
- printf("You did not enter in anything.\n");
- }
- if(result)
- printf("You successfully did the thing!");
- else
- printf("You did not successfully do the thing.");
- return 0;
- }//end main
- bool function1(char* fileN){
- FILE* fIn = fopen(fileN,"r");
- if(fIn == NULL)
- return false;
- else{
- fclose(fIn);
- return true;
- }
- }//end function
- void FlushInput(void){
- while(getchar() != '\n');
- return;
- }//end function
- bool function2(char* textIn, char* fName){
- FILE* fPtr = fopen(fName,"w");
- if(fPtr == NULL){
- printf("Error.\n");
- return false;
- }
- else{
- fputs(textIn, fPtr);
- fclose(fPtr);
- return true;
- }//end if-else
- }//end function
Add Comment
Please, Sign In to add comment