Question

In: Computer Science

Create a c file to read from an existing file one character at a time and...

Create a c file to read from an existing file one character at a time and print that character to the console

Create a c file to read a character from the standard input and write it to a file.

please help me

Solutions

Expert Solution

Code:

#include<stdio.h>
int main()
{
   char ch;
   FILE *file; //file pointer decleration
   file=fopen("text.txt","r"); //open file in read mode
   if (file == NULL)
printf("Can not open file\n"); //could not open file
else // file open successfully
{
   ch =fgetc(file); //read first charecter in ch
   while(ch!=EOF) // run untill the last charecter of file
       {
           printf("%c",ch); //print charecter by charecter in console
           ch=fgetc(file); //point next charecter
       }
   }
   fclose(file); //close the file
   return 0;
}

text file:

Output:

2nd code to write char in file:

#include <stdio.h>

int main()
{
   FILE *fptr; // creating a FILE variable
char ch; // creating a character variable
   fptr = fopen("test.txt", "w"); // open the file in write mode
   printf("Enter a charecter\n");
   scanf("%c",&ch); // take user input
putc(ch, fptr); // write character ch in file
printf("Write in file successfully");
   fclose(fptr); // close the file
}

Output file:

Output:


Related Solutions

C++ question: When cleaning a file the existing data is often read by character. Once a...
C++ question: When cleaning a file the existing data is often read by character. Once a file has been cleaned it is rarely read in by character. Explain Why?
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
I need C++ program that Read an input file of text.txt one word at a time....
I need C++ program that Read an input file of text.txt one word at a time. The file should consist of about 500 words. The program should remove all punctuations,keep only words. Store the words in a built-in STL container, such as vector or map.Can someone help with any additional comments that I can understand the logic?thank you
Done in c++ Read this file one time to determine how many records it contains. Be...
Done in c++ Read this file one time to determine how many records it contains. Be sure to check for a successful file open here. Close the file. Allocate memory dynamically to store the data from step 1. This dynamically allocated memory should be for an array of strings. The array size should be exactly the number of records from step 1. Reopen the file and read it a second time, storing each record into the array of strings from...
Write a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
language c++(Data structure) You have to read a file and store a data in character array...
language c++(Data structure) You have to read a file and store a data in character array ( you cant initialize a character array, you have to code generically) code must be generic u must read a file onece u cant use built in function etc string, code in classes if u initialized a char array or ur code doesn't run i will dislike and report u you can use link list to store data
In C++, The following program reads one character from the keyboard and will display the character...
In C++, The following program reads one character from the keyboard and will display the character in uppercase if it is lowercase and does the opposite when the character is in uppercase. If the character is a digit, it displays a message with the digit. Modify the program below such that if one of the whitespaces is entered, it displays a message and tells what the character was. // This program reads one character from the keyboard and will //...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
A. Open/create the file bank.txt for writing "w". Enter a character from the keyboard and write...
A. Open/create the file bank.txt for writing "w". Enter a character from the keyboard and write it to the file. Close the file. In the same program open the file for reading "r" and read the character from the file and print it on screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT