SlideShare a Scribd company logo
1 of 13
import java.util.*;
import java.io.*;
public class TextFileInfoPrinter
{
public static void main(String[]args) throws FileNotFoundException
{
Scanner console= new Scanner(System.in);
System.out.println("File to be read: ");
String inputFile = console.next();
File file = new File(inputFile);
Scanner in = new Scanner(file);
int words = 0;
int lines = 0;
int chars = 0;
while(in.hasNext())
{
in.next();
words++;
}
while(in.hasNextLine())
{
in.nextLine();
lines++;
}
while(in.hasNextByte())
{
in.nextByte();
chars++;
}
System.out.println("Number of lines: " + lines);
System.out.println("Number of words: " + words);
System.out.println("Number of characters: " + chars);
}
}
Programto countno ofcharacters
ifstream infile;
//char mystring[6];
//char mystring[20];
int main()
{
infile.open("file.txt");
if(infile.fail())
{
cout << " Error " << endl;
}
int numb_char=0;
char letter;
while(!infile.eof())
{
infile.get(letter);
cout << letter;
numb_char++;
}
cout << " the number of characters is :" << numb_char << endl;
infile.close();
return 0;
}
Countsno of lines,words andcharacters
#include<iostream>
#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
// start of main program
int main()
{
string filename;
cout<<"Please enter the data filename: ";
// reads the filename fromthe user
cin>>filename;
// open the filefor input.
ifstream infile(filename, std::ifstream::in);
// create the stream in read-only mode
if(!infile){
cout << "Cannot open file for reading.n";
_getch();
return 1;
}
// declares character and integer variables
char ch,c;
int count=1;
int i=0;
int count1=1;
// running the loop until file willend
while(infile.get(ch))
{
cout<<ch;
if(ch==' ')
{
count++;
count1++;
}
else if(ch==' ')
count1++;
i=i+1;
}
cout<<"";
// display the number of character, words and line
cout<<"nNumber of characters: "<<i-(count-1+count1-1)<<"";
cout<<"nNumber of words: "<<count1<<"";
cout<<"nNumber of lines: "<<count<<"";
// closes the file
infile.close();
_getch();
return 0;
}
Write a c programto count the numberof character,numberof linesina file
#include<stdio.h>
#include<conio.h>
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf("n enter the source file name");
gets(fname);
fr=fopen(fname,"r");
if(fr==NULL)
{
printf("n error n");
exit(0);
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc++;
if(ch==' ');
now++;
if(ch=='n')
{
nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
printf("n total no of character=%d",noc);
printf("n total no of words=%d",now);
printf("n total no of lines=%d",nol);
getch();
}
Occurences of aword in text file
#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main()
{
ifstream fin("my_data.txt");//opening text file
int count=0;
char ch[20],c[20];
cout<<"Enter a word to count:";
gets(c);
while(fin)
{
fin>>ch;
if(strcmp(ch,c)==0)
count++;
}
cout<<"Occurrence="<<count<<"n";
fin.close();//closing file
return 0;
}
Question2
/*************************************************
* C program to count no of lines, wordsand *
* characters in a file. *
*************************************************/
#include <stdio.h>
int main()
{
FILE *fp;
char filename[100];
char ch;
int linecount, wordcount,charcount;
// Initialize counter variables
linecount = 0;
wordcount= 0;
charcount = 0;
// Prompt user to enter filename
printf("Enter a filename :");
gets(filename);
// Open file in read-only mode
fp = fopen(filename,"r");
// If file opened successfully, then write the string to file
if ( fp )
{
//Repeat until End Of File character is reached.
while ((ch=getc(fp))!=EOF){
// Increment character count if NOTnew line or space
if (ch!= ' ' && ch != 'n') { ++charcount; }
// Increment word count if new line or space character
if (ch == ' ' ||ch == 'n') { ++wordcount;}
// Increment line count if new line character
if (ch == 'n'){ ++linecount; }
}
if (charcount > 0) {
++linecount;
++wordcount;
}
}
else
{
printf("Failed to open the filen");
}
printf("Lines : %d n", linecount);
printf("Words: %d n", wordcount);
printf("Characters : %d n", charcount);
getchar();
return(0);
}
C Programto count characters,lines,spaces& tabs in a file.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char a[20];
int nol=0,not=0,nob=0,noc=0;
char c;
clrscr();
printf("Enter the name of File:n");
gets(a);
if((fp=fopen(a,"r"))==NULL)
{
printf("File dosen't exist.");
}
else
{
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
noc++;
if(c==' ')
nob++;
if(c=='n')
nol++;
if(c=='t')
not++;
}
}
fclose(fp);
printf("Number of characters = %dn",noc);
printf("Number of blanks = %dn",nob);
printf("Number of tabs = %dn",not);
printf("Number of lines = %dn",nol);
getch();
}
Programcountsno occurrences ofcertainwordintext file
int WordCount ::countWords(string wrd)
{
int counter=0;
string temp = "";
while (getline(*file,temp))
{
for (int i = 0; i < temp.length();i++)
{
if (tolower(temp[i]+ temp[i+1] + temp[i+2]) == (wrd[0]+ wrd[1] + wrd[2]))
{
counter++;
}
else if (toupper(temp[i] + temp[i+1] + temp[i+2]) == toupper(wrd[0] + wrd[1] + wrd[2]))
{
counter++;
}
}
}
return counter;
}

More Related Content

What's hot

File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CMahendra Yadav
 
File handling in C++
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7Ananda Kumar HN
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with exampleSunil Patel
 
File handling in c
File handling in c File handling in c
File handling in c Vikash Dhal
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in CTushar B Kute
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examplesMuhammed Thanveer M
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with pythonDEEPAKSINGHBIST1
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)Amit Ghosh
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
 

What's hot (20)

File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
Dill
DillDill
Dill
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
 
File handling in c
File handling in c File handling in c
File handling in c
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with python
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
File_Management_in_C
File_Management_in_CFile_Management_in_C
File_Management_in_C
 
Files in c++
Files in c++Files in c++
Files in c++
 
File Pointers
File PointersFile Pointers
File Pointers
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 

Viewers also liked

Question 4
Question 4Question 4
Question 4ArchieC
 
Movimiento de tierras presentacion
Movimiento de tierras presentacionMovimiento de tierras presentacion
Movimiento de tierras presentacionMarianella241990
 
Λογισμικό
ΛογισμικόΛογισμικό
ΛογισμικόMariaProGr
 
Presentacion sobre rss
Presentacion sobre  rssPresentacion sobre  rss
Presentacion sobre rssanyi22campo
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mulePhaniu
 
For each component in mule demo
For each component in mule demoFor each component in mule demo
For each component in mule demoSudha Ch
 
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...Uploadworld
 
Safe navigation operator in Ruby
Safe navigation operator in RubySafe navigation operator in Ruby
Safe navigation operator in RubyKoichi ITO
 
The Challenges of Affect Detection in the Social Programmer Ecosystem
The Challenges of Affect Detection in the Social Programmer EcosystemThe Challenges of Affect Detection in the Social Programmer Ecosystem
The Challenges of Affect Detection in the Social Programmer EcosystemNicole Novielli
 
Stack Overflow DK Recruitment Day 2015 Presentation
Stack Overflow DK Recruitment Day 2015 PresentationStack Overflow DK Recruitment Day 2015 Presentation
Stack Overflow DK Recruitment Day 2015 PresentationAngela Nyman
 
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...Fairfax County
 
Emergency Vehicle Preemption
Emergency Vehicle PreemptionEmergency Vehicle Preemption
Emergency Vehicle PreemptionFairfax County
 
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016Fairfax County
 

Viewers also liked (17)

Mule splitters
Mule splittersMule splitters
Mule splitters
 
Question 4
Question 4Question 4
Question 4
 
Movimiento de tierras presentacion
Movimiento de tierras presentacionMovimiento de tierras presentacion
Movimiento de tierras presentacion
 
Λογισμικό
ΛογισμικόΛογισμικό
Λογισμικό
 
Presentacion sobre rss
Presentacion sobre  rssPresentacion sobre  rss
Presentacion sobre rss
 
Tabla paso 2
Tabla paso 2Tabla paso 2
Tabla paso 2
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mule
 
Python lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
Python lab - Βασικές Αρχές Προγραμματισμού ΕργαστήριοPython lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
Python lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
 
For each component in mule demo
For each component in mule demoFor each component in mule demo
For each component in mule demo
 
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...
Comprehensive study on pharmacognostic, physico and phytochemical evaluation ...
 
Safe navigation operator in Ruby
Safe navigation operator in RubySafe navigation operator in Ruby
Safe navigation operator in Ruby
 
The Challenges of Affect Detection in the Social Programmer Ecosystem
The Challenges of Affect Detection in the Social Programmer EcosystemThe Challenges of Affect Detection in the Social Programmer Ecosystem
The Challenges of Affect Detection in the Social Programmer Ecosystem
 
Stack Overflow DK Recruitment Day 2015 Presentation
Stack Overflow DK Recruitment Day 2015 PresentationStack Overflow DK Recruitment Day 2015 Presentation
Stack Overflow DK Recruitment Day 2015 Presentation
 
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...
Reston Transportation Funding Plan: Funding Scenarios and Advisory Group Work...
 
Emergency Vehicle Preemption
Emergency Vehicle PreemptionEmergency Vehicle Preemption
Emergency Vehicle Preemption
 
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016
Springfield Multi-Use Parking Garage: Public Information Meeting Aug. 17, 2016
 
Algebra b 1
Algebra b 1Algebra b 1
Algebra b 1
 

Similar to source code which create file and write into it

Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdfarshiartpalace
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfsangeeta borde
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptxradhushri
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in cyazad dumasia
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageESUG
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
Here is my code. There are Two C Programs which need to follow the a.pdf
Here is my code. There are Two C Programs which need to follow the a.pdfHere is my code. There are Two C Programs which need to follow the a.pdf
Here is my code. There are Two C Programs which need to follow the a.pdffcaindore
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfshahidqamar17
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10patcha535
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfaratextails30
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfpratyushraj61
 

Similar to source code which create file and write into it (20)

C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
Lab4
Lab4Lab4
Lab4
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Here is my code. There are Two C Programs which need to follow the a.pdf
Here is my code. There are Two C Programs which need to follow the a.pdfHere is my code. There are Two C Programs which need to follow the a.pdf
Here is my code. There are Two C Programs which need to follow the a.pdf
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
 
Files
FilesFiles
Files
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
5java Io
5java Io5java Io
5java Io
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
 

Recently uploaded

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Recently uploaded (20)

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

source code which create file and write into it

  • 1. import java.util.*; import java.io.*; public class TextFileInfoPrinter { public static void main(String[]args) throws FileNotFoundException { Scanner console= new Scanner(System.in); System.out.println("File to be read: "); String inputFile = console.next(); File file = new File(inputFile); Scanner in = new Scanner(file); int words = 0; int lines = 0; int chars = 0; while(in.hasNext()) { in.next(); words++; } while(in.hasNextLine()) { in.nextLine(); lines++; } while(in.hasNextByte()) {
  • 2. in.nextByte(); chars++; } System.out.println("Number of lines: " + lines); System.out.println("Number of words: " + words); System.out.println("Number of characters: " + chars); } } Programto countno ofcharacters ifstream infile; //char mystring[6]; //char mystring[20]; int main() { infile.open("file.txt"); if(infile.fail()) { cout << " Error " << endl; } int numb_char=0; char letter; while(!infile.eof())
  • 3. { infile.get(letter); cout << letter; numb_char++; } cout << " the number of characters is :" << numb_char << endl; infile.close(); return 0; } Countsno of lines,words andcharacters #include<iostream> #include<fstream> #include<string> #include<conio.h> using namespace std; // start of main program int main() { string filename; cout<<"Please enter the data filename: ";
  • 4. // reads the filename fromthe user cin>>filename; // open the filefor input. ifstream infile(filename, std::ifstream::in); // create the stream in read-only mode if(!infile){ cout << "Cannot open file for reading.n"; _getch(); return 1; } // declares character and integer variables char ch,c; int count=1; int i=0; int count1=1; // running the loop until file willend while(infile.get(ch)) { cout<<ch; if(ch==' ') {
  • 5. count++; count1++; } else if(ch==' ') count1++; i=i+1; } cout<<""; // display the number of character, words and line cout<<"nNumber of characters: "<<i-(count-1+count1-1)<<""; cout<<"nNumber of words: "<<count1<<""; cout<<"nNumber of lines: "<<count<<""; // closes the file infile.close(); _getch(); return 0; } Write a c programto count the numberof character,numberof linesina file #include<stdio.h> #include<conio.h>
  • 6. void main() { int noc=0,now=0,nol=0; FILE *fw,*fr; char fname[20],ch; clrscr(); printf("n enter the source file name"); gets(fname); fr=fopen(fname,"r"); if(fr==NULL) { printf("n error n"); exit(0); } ch=fgetc(fr); while(ch!=EOF) { noc++; if(ch==' '); now++; if(ch=='n')
  • 7. { nol++; now++; } ch=fgetc(fr); } fclose(fr); printf("n total no of character=%d",noc); printf("n total no of words=%d",now); printf("n total no of lines=%d",nol); getch(); } Occurences of aword in text file #include<iostream.h> #include<fstream.h> #include<string.h> int main() { ifstream fin("my_data.txt");//opening text file int count=0;
  • 8. char ch[20],c[20]; cout<<"Enter a word to count:"; gets(c); while(fin) { fin>>ch; if(strcmp(ch,c)==0) count++; } cout<<"Occurrence="<<count<<"n"; fin.close();//closing file return 0; } Question2 /************************************************* * C program to count no of lines, wordsand * * characters in a file. * *************************************************/ #include <stdio.h>
  • 9. int main() { FILE *fp; char filename[100]; char ch; int linecount, wordcount,charcount; // Initialize counter variables linecount = 0; wordcount= 0; charcount = 0; // Prompt user to enter filename printf("Enter a filename :"); gets(filename); // Open file in read-only mode fp = fopen(filename,"r"); // If file opened successfully, then write the string to file if ( fp ) { //Repeat until End Of File character is reached. while ((ch=getc(fp))!=EOF){ // Increment character count if NOTnew line or space if (ch!= ' ' && ch != 'n') { ++charcount; }
  • 10. // Increment word count if new line or space character if (ch == ' ' ||ch == 'n') { ++wordcount;} // Increment line count if new line character if (ch == 'n'){ ++linecount; } } if (charcount > 0) { ++linecount; ++wordcount; } } else { printf("Failed to open the filen"); } printf("Lines : %d n", linecount); printf("Words: %d n", wordcount); printf("Characters : %d n", charcount); getchar();
  • 11. return(0); } C Programto count characters,lines,spaces& tabs in a file. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { FILE *fp; char a[20]; int nol=0,not=0,nob=0,noc=0; char c; clrscr(); printf("Enter the name of File:n"); gets(a); if((fp=fopen(a,"r"))==NULL) { printf("File dosen't exist."); } else { while(1) { c=fgetc(fp); if(c==EOF) break;
  • 12. noc++; if(c==' ') nob++; if(c=='n') nol++; if(c=='t') not++; } } fclose(fp); printf("Number of characters = %dn",noc); printf("Number of blanks = %dn",nob); printf("Number of tabs = %dn",not); printf("Number of lines = %dn",nol); getch(); } Programcountsno occurrences ofcertainwordintext file int WordCount ::countWords(string wrd) { int counter=0; string temp = ""; while (getline(*file,temp)) { for (int i = 0; i < temp.length();i++) { if (tolower(temp[i]+ temp[i+1] + temp[i+2]) == (wrd[0]+ wrd[1] + wrd[2]))
  • 13. { counter++; } else if (toupper(temp[i] + temp[i+1] + temp[i+2]) == toupper(wrd[0] + wrd[1] + wrd[2])) { counter++; } } } return counter; }