How to write a C Program Writing a character into a file,reading the character from the console and writing the next letter into the file in C Programming Language ?
Solution:
/* Writing a character into a file,reading the character from the console and writing the next letter into the file*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp; //creates a file pointer
char ch;
int con;
fp=fopen("filehandling.txt","w+"); // creates a text file with label "filehandling" in write mode
if(fp==NULL) //checks for the filename validity
{
printf("\nUnable to open the file\n");
exit(0);
}
printf("\nFile opened successfully\n");
printf("\nEnter the character as input\n");
scanf("%c",&ch);
putc(ch,fp);
fclose(fp);
fp=fopen("filehandling.txt","rwa+");
ch=getc(fp);
con=ch;
con++;
if(con>=97 && con<122)
{
fprintf(fp,"\nthe next char is %c\n",con);
}
else
{
fprintf(fp,"\nthe next char is a\n");
fclose(fp);
// open filehandling.txt file and check the input and output given...
}
}
Learn More :
Pointer
- C Program Pointer Example
- C Program To Reverse The String Using Pointer
- C Program to Find max and min in array using pointer concept
- C Program to Adds literal to list of literals
- C Program to find smallest in an array using pointer
- C Program A simple demonstration of using pointers to determine which function to use
- C Program LEXICAL ANALYSER
- C Program Simple linked list
File
- COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM
- C Program File Input & Output Example
- C Program To Destruc Self Execution File ?
- C Program To Store Students Record In A Text File
- C Program To Write Data In A File And Search Data From File
- Make a copy of file given in argv[1] to file given in argv[2]
- C Program to copy a file to another file
- C Function to read instructions from the file and obey them
- Client/Server C program to make client send the name of a file
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program to Read and Write FIFO
- File Number Control C Program Example
- C Program to opens and reads dictionary file specified in spellrc
- C Program to Recursively converts all file-names to lower-case
- C Program to Find the Size of File using File Handling Function
- C Program Recursive function that searches for a given file in a given folder
- C Program Read a char & print next char ( file to file )
- C Program to Input Student Details into a File For Two Subjects
- Identifies the architecture Windows PE (exe or dll) file was compiled C Program
File Handling
Letter
Console
- How To Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.
- C Program to Defines the entry point for the console application
- C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result
- C Program to Defines the entry point for the console application
- Defines the entry point for the console application.
Characters
- C Program Character toupper() Example
- C Program Character Example
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Copy One Character Array Into Another
- C Program to Print ASCII equivalent of a character until terminated by key is ‘x’
- C Program to find the number of unique characters
- Printing ASCII Table with Numbers and corresponding characters
- C Program to Compare Two Character
- Design a C function that shortens a string to 8 characters
- Menu driven program in C which performs the following operations on strings