really really simple program, but gets and puts not working,........can somebody spot the bug?
<\code>
#include<iostream>
#include<fstream>
#include"stdio.h"
//Main Function
int main()
{
cout<<"Hello World"<<endl;
cout<<"\t\tWelcome to the Encryptonator-Decryptonator..."<<endl<<endl;
cout<<"What do you want to do?..."<<endl;
cout<<"1. Encrypt...(1)\n2. Decrypt...(2)\n3. Exit...(3)\n";
cin>>choice;
You declared 'name' to be a char array, not an std::ifstream, and it isn't initialized. You need to pass a file name to an std::ifstream constructor before your call to the "gets()" function, and have that stream as your argument to both "gets()" and "puts()".
My bad I mixed up the gets and puts functions. I thought they were like "get()" and "put()" where they are member functions of stream objects but they're not so ignore my last post.
You seem to be running into the trap that most beginners hit, the "<<" operator leaves white space in the stream. So when you get to the point where you're calling "gets()" it sees the newline character and immediately returns.
I'll put my EDIT down here so that I know you see it.
Try flushing the stream cin.sync(); before you call "gets()".
EDIT: When I say "try" it's not because I'm guessing, I want you to actually write it and see what happens. The "sync()" function will essentially eat the newline character so that "gets()" doesn't see it.
EDIT: The new line character was put in when you hit Enter after making your choice. This doesn't just disappear, it sits in the stream and waits for something to remove it which neither the "<<" operator or the "gets()" function do.