1)Define a function Intext(), to create a text file named Story.txt, which should contain text lines entered by the user.
Define another function Outtext , to read and display each word of the text file Story.txt on different lines on screen.
Write a program which uses the above two function to create and display the contents of the text file Story.txt
OUTPUT:
Enter text:
Trees are the best friend of man on Earth.
Continue?(y/n): y
Enter text:
Trunks of the trees have concentric rings in their cross section.
Continue?(y/n): n
Trees
are
the
best
friend
of
man
on
Earth.
Trunks
of
the
trees
have
concentric
rings
in
their
cross
section.
2)Write a program which uses a function RevText(), to read the contents of the text file Story.txt (created using above program), and prints in reverse of those lines which start with an alphabet 'T'.
@DTSCode
Why should a) be int main()? The function main doesn't return any integer value. Rather it executed statements which is considered to be void type. So why would it be int main() and not void main()?
it used to be void main, but the standard was changed. it actually does return an int, but it is not required to explicitly write returnint. its like constructors. c++ will generate an initial constructor for you if you dont have one. in the main function it will have implicitly return (i think) 0 (it might be one) if you dont have it return something else
a) i would try flushing the input buffer
b) whats up with the first while loop in the second program. its unneccesary and pointless.
c) can you use std::string? it would make this program a lot cleaner
remove the second while loop. it grabs the first line, tests for the T, and if its there grabs the next line and reverses it. your structure should look like this:
while(...)
if(...)
for(...)
notice that there is no while loop between the if and the for, like in your code