TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CYBER CON
from: ANTHONY TIBBS
date: 1998-01-27 18:58:00
subject: C++ Saveding stuff

CC> ok i know how you have some one enter a number
CC> scanf , but will this work for words.
CC> so could someone write me a exp. program that does the following.
  Yet another alias....
Well, first of all, is this your homework?  :)  Secondly...
   ----- CYBER.CPP begins -----
#include 
#include 
#include 
// Write their name to a file...
void Write_To_File (char *pszFilename, char *pszUsrName)
{
FILE *hFile;
   if (!pszFilename || !pszUsrName)    /* Idiot proof it... */
      return;
   hFile = fopen (pszFilename, "w");
   if (!hFile)
   {
      // The following is sloppy to prevent editor wrapping...
      
      cerr << "Error: Unable to open file, \"" <<
                                               pszFilename << "\"!"
                                               << endl;
      return;
   }
   fputs (pszUsrName, hFile);
   fclose (hFile);
}
// Read their name from a file...
void Read_From_File (char *pszFilename, char *pszUsrName, int nBufLen)
{
FILE *hFile;
   if (!pszFilename || !pszUsrName)    /* Idiot proof it... */
      return;
   if (nBufLen <= 1)
      return;
   hFile = fopen (pszFilename, "r");
   if (!hFile)
   {
      // The following is sloppy to prevent editor wrapping...
      
      cerr << "Error: Unable to open file, \"" <<
                                               pszFilename << "\"!"
                                               << endl;
      return;
   }
   fgets (pszUsrName, nBufLen, hFile);
   fclose (hFile);
}
int main (void)
{
char szName [512];         /* That should be lots large enough. */
   //
   // Display a prompt and get the users name...
   //
   cout << "Enter your name: ";
   cin >> szName;
   //
   // Check to see if their name is "Cyber Con" (case insensitive)
   //
   if (!strcmpi(szName, "Cyber Con"))
      cout << endl << "Hi, Cyber Con!" << endl;
   Write_To_File ("FILE1.FIL", szName);
   Read_From_File ("FILE1.FIL", szName, 512);
   cout << "User name from file is: " << szName << endl;
   return 0;
}
   ----- CYBER.CPP ends -----
--- PointEd 2.0
---------------
* Origin: The Tibbs' Point - Ottawa, Ontario, Canada (1:163/215.38)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.