Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream.h>
- #include<conio.h>
- #include<string.h>
- #include<stdio.h>
- #include <ctype.h>
- void func()
- {
- char stream[80],name[100];
- int a = 0;
- cout << "Enter the name of the text file: " << endl;
- gets(name);
- cout << "Enter the sentence you want to insert in the file: ";
- gets(stream);
- ofstream fout(name);
- fout << stream;
- fout.close();
- ofstream copy("copy.txt");
- ifstream fin(name);
- cout << "nWords in copy.txt:" << endl;
- while(!fin.eof())
- {
- fin.getline(stream,80,' ');
- if(fin.eof())
- break;
- a = strlen(stream)-1;
- if(stream[a] == '.' || stream[a] == '?' || stream[a] == '!' || stream[a] == '"') //followed by punctuarion mark
- {
- if((isalpha(stream[a-1])) && !(tolower(stream[a-1]) == 'a'|| tolower(stream[a-1]) == 'e'|| tolower(stream[a-1]) == 'i'|| tolower(stream[a-1]) == 'o'|| tolower(stream[a-1]) == 'u'))
- {
- copy << stream << ' ';
- cout << stream << ' ';
- }
- }
- else if((isalpha(stream[a])) && !(tolower(stream[a]) == 'a'|| tolower(stream[a]) == 'e'|| tolower(stream[a]) == 'i'|| tolower(stream[a]) == 'o'|| tolower(stream[a]) == 'u'))
- {
- copy << stream << ' ';
- cout << stream << ' ';
- }
- }
- }
- void main()
- {
- clrscr();
- func();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement