Question

(c programming) Given the function declaration and documentation below, write the function definition. Do not use...

(c programming)

Given the function declaration and documentation below, write the function definition. Do not use the the standard library function fputc.

/// @brief Writes a character to a specified file output stream.
/// @param outstream A FILE* variable for an output stream to write a character to.
/// @param outchar The character to be written to an output stream.
/// @return On success, returns the written character. 
/// @note This function assumes #include <stdio.h> and a working, valid FILE* variable to an output stream.
char placechar(FILE* outstream, char outchar);

Homework Answers

Answer #1

char placechar(File* outstream, char outchar);

its function definition is below:



char placechar(FILE* outstream, char outchar){

    //writing data of specified format to file  
    //fprintf will return the no. of characters
    // written to file on success
    int res = fprintf(outstream, "%c",outchar);
    
    //if character has been written to file
    if(res == 1)
        return outchar;

    //closing file  
    fclose(outstream);

    return '\0';
}

Output:

if it helps you, do upvote as it motivates us a lot!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(c programming) Given the function declaration and documentation below, write the function definition. Do not use...
(c programming) Given the function declaration and documentation below, write the function definition. Do not use the standard library function fgetc. /// @brief Reads a character from specified file input stream. /// @param instream A FILE* variable for an input stream to read a character from. /// @return A character of type char from instream. /// @note This function assumes #include <stdio.h> and a working, valid FILE* variable to an input stream. char grabchar(FILE* instream);
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
Following are the most important file management functions available in C. Use any 6 of them...
Following are the most important file management functions available in C. Use any 6 of them in your program and show the output. Function purpose fopen () Creating a file or opening an existing file fclose () Closing a file fprintf () Writing a block of data to a file fscanf () Reading a block data from a file getc () Reads a single character from a file putc () Writes a single character to a file getw () Reads...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
(Do this in C++ please and make sure no compile/run errors): I. Write a function that...
(Do this in C++ please and make sure no compile/run errors): I. Write a function that writes a series of random Fahrenheit temperatures and their correspond- ing Celsius temperatures to a tab-delimited file. Use 32 to 212 as your temperature range. From the user, obtain the following: 1. The number of temperatures to randomly generate. 2. The name of the output file. A sample run is included below (you must follow the format provided below): Please enter the name of...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Please answer the following C question: There is a documented prototype for a function called get_a_line...
Please answer the following C question: There is a documented prototype for a function called get_a_line in the code below. Write a definition for get_a_line—the only function called from that definition should be fgetc. #include <stdio.h> #include <string.h> #define BUFFER_ARRAY_SIZE 10 int get_a_line(char *s, int size, FILE *stream); // Does what fgets does, using repeated calls to fgetc, but // provides a more useful return value than fgets does. // // REQUIRES // size > 1. // s points to...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT