SlideShare a Scribd company logo
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;
}
Ad

More Related Content

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
Mahendra Yadav
 
Dill
DillDill
Dill
DhilLanurfadillah Whijathozhoppenk
 
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 7
Ananda 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 example
Sunil Patel
 
File handling in c
File handling in c File handling in c
File handling in c
Vikash Dhal
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
HalaiHansaika
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
Tushar 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 examples
Muhammed Thanveer M
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with python
DEEPAKSINGHBIST1
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
Amit Ghosh
 
Functions in python
Functions in pythonFunctions in python
Functions in python
Santosh Verma
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
File_Management_in_C
File_Management_in_CFile_Management_in_C
File_Management_in_C
NabeelaNousheen
 
Files in c++
Files in c++Files in c++
Files in c++
NivethaJeyaraman
 
File Pointers
File PointersFile Pointers
File Pointers
Kulachi Hansraj Model School Ashok Vihar
 
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
 
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
Mahendra 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 7
Ananda 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 example
Sunil 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 C
Tushar 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 examples
Muhammed Thanveer M
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with python
DEEPAKSINGHBIST1
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil 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++ ppt
Kumar
 
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
 

Viewers also liked (17)

Mule splitters
Mule splittersMule splitters
Mule splitters
Ravinder Singh
 
Question 4
Question 4Question 4
Question 4
ArchieC
 
Movimiento de tierras presentacion
Movimiento de tierras presentacionMovimiento de tierras presentacion
Movimiento de tierras presentacion
Marianella241990
 
Λογισμικό
ΛογισμικόΛογισμικό
Λογισμικό
MariaProGr
 
Presentacion sobre rss
Presentacion sobre  rssPresentacion sobre  rss
Presentacion sobre rss
anyi22campo
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mule
Phaniu
 
Python lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
Python lab - Βασικές Αρχές Προγραμματισμού ΕργαστήριοPython lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
Python lab - Βασικές Αρχές Προγραμματισμού Εργαστήριο
Pavlos (Παύλος) Avgerinopoulos (Αυγερινόπουλος)
 
For each component in mule demo
For each component in mule demoFor each component in mule demo
For each component in mule demo
Sudha 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 Ruby
Koichi 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 Ecosystem
Nicole 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 Presentation
Angela 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 Preemption
Fairfax 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, 2016
Fairfax County
 
Algebra b 1
Algebra b 1Algebra b 1
Algebra b 1
Christos Loizos
 
Question 4
Question 4Question 4
Question 4
ArchieC
 
Movimiento de tierras presentacion
Movimiento de tierras presentacionMovimiento de tierras presentacion
Movimiento de tierras presentacion
Marianella241990
 
Λογισμικό
ΛογισμικόΛογισμικό
Λογισμικό
MariaProGr
 
Presentacion sobre rss
Presentacion sobre  rssPresentacion sobre  rss
Presentacion sobre rss
anyi22campo
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mule
Phaniu
 
For each component in mule demo
For each component in mule demoFor each component in mule demo
For each component in mule demo
Sudha 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 Ruby
Koichi 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 Ecosystem
Nicole 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 Presentation
Angela 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 Preemption
Fairfax 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, 2016
Fairfax County
 
Ad

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

C Programming Project
C Programming ProjectC Programming Project
C Programming Project
Vijayananda Mohire
 
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
arshiartpalace
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan 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.pdf
sangeeta borde
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
Dushmanta Nath
 
Lab4
Lab4Lab4
Lab4
siragezeynu
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
radhushri
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptxObject Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptxObject Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
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
yazad 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 Language
ESUG
 
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
PRATIKSINHA7304
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
Daniel Nyagechi
 
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
fcaindore
 
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
shahidqamar17
 
DOC-20241121-WA0004bwushshusjssjuwh..pdf
DOC-20241121-WA0004bwushshusjssjuwh..pdfDOC-20241121-WA0004bwushshusjssjuwh..pdf
DOC-20241121-WA0004bwushshusjssjuwh..pdf
TanishaWaichal
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
patcha535
 
Introduction to files management systems
Introduction to files management systemsIntroduction to files management systems
Introduction to files management systems
araba8
 
Files
FilesFiles
Files
Karthika Parthasarathy
 
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
aratextails30
 
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
arshiartpalace
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan 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.pdf
sangeeta borde
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
Dushmanta Nath
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
radhushri
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptxObject Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptxObject Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
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
yazad 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 Language
ESUG
 
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
PRATIKSINHA7304
 
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
fcaindore
 
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
shahidqamar17
 
DOC-20241121-WA0004bwushshusjssjuwh..pdf
DOC-20241121-WA0004bwushshusjssjuwh..pdfDOC-20241121-WA0004bwushshusjssjuwh..pdf
DOC-20241121-WA0004bwushshusjssjuwh..pdf
TanishaWaichal
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
patcha535
 
Introduction to files management systems
Introduction to files management systemsIntroduction to files management systems
Introduction to files management systems
araba8
 
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
aratextails30
 
Ad

Recently uploaded (20)

Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 

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; }
  翻译: