I am trying to create a login program that is supposed to create a different txt file for every sign up. but for sum reason when i sign up it doesn't create any txt file at all. befroe I added it in that it creates a different txt file for each different signup it worked perfectly. Can someone help me??
Code:#include <fstream.h> //include everything that is nessacary #include <iostream.h> #include <string.h> #include <stdlib.h> int login() { char nuttin[2];//initialize my variables char read[10]; char siname[10]; char sipass[10]; char txt[10]; cout<<"Please Enter Your User Name:\t";//ask for a user name cin>>siname;//write the name to siname siname=txt; strcat(txt,".txt"); ifstream d_file(txt);//open username.txt cout<<"Please Enter Your Password:\t";//ask for a password cin>>sipass;//write the password to sipass strcat(siname, ".");//add a period at the end of siname strcat(siname, sipass);// combine the two to create a variable contiaining "username.password" d_file>>read;//write the contents of username.txt to a variable if (strcmp(read,siname) == 0) //compare the variables { cout<<"You Have Succesfully Logged In:\n";//explain the login was successful system("PAUSE");//end the program return 0; } else { cout<<"\nYour Log In Was Unsuccessful.Quit. Then Restart The Program To Try Again Or Sign Up\n"; //explain something went wrong and give directions on what to do system("PAUSE");//end the program return 0; } } int signup() { char name[10]; //Create My Variables char password[10]; char str[22]; char jeff[10]; cout<<"Please Create A User Name Less Then 10 Letters:\t";//ask for a user name cin>>name;//write to user name cout<<"Please Create A Password Less Then 10 Letters:\t";//ask for a password cin>>password;//write to password name=jeff;//made it so that we have a variable that is their username that we can add on to but not destroy the username strcat(jeff,".txt");//adds .txt to the end of username ofstream a_file(jeff);//creates file with the name of username a_file << name << "." << password;//write the username "." Password to the file a_file.close(); //close the file cout<<"\n Your Sign Up Was Successful. Thank You.\n"; //explain they are now signed up system("PAUSE");//end the program return 0; //return a integer } int main() { int k; cout<<"\t\t******** Welcome to Login Program *********************";//some pretty ouput to tell them where they are cout<< "\n 1: LOGIN\n 2: SIGN UP\n 3: EXIT\n Please Make your Choice:";//output their choices and ask for theirs cin>>k;//input their choice and write it to k if (k==1)//cheak if k=login { login();//if it does then execute the login function } else if(k==2) //see if k= signup { signup();} else if(k==3) {return 0;} }



LinkBack URL
About LinkBacks


