Jump to content

Work In Progress


Recommended Posts

So... what's wrong so far?

 

/*Sam's DOS Writing Thinger*/
/*Coding assistance provided by:
**Mark C.**/

#include <iostream>
#include <string>
#include <stdio.h> //stdio.h contains the proper library for the function we're using

using namespace std;

string directoryName;
string fileName;
string userEntry;
string password;

char passwordProtect;

string openFileWithDirectory(string,string);
string openFileNew(string,string,string);

int readOrWrite;
int main(void) {
   cout << "\n\nWelcome to Sam's DOS Writing Thinger! Would you like to make a new file, or edit an existing one?\n" \
           "1: New File\n2:Edit Existing File\n>";
   cin >> readOrWrite
   
   switch (readOrWrite) {
       case(1) { cout << "\n\nEnter a filename, followed by a .txt: ";
                 cin >> fileName;
                 
                 cout << "\nNow, enter in the words: \n";
                 cin >> userEntry;
                 
                 openFileNew(fileName,FileDirectory,userEntry);
                 
             }
             
             default { int 1; } // =D
             
             }
       return 0;
       
   }    
                 

string openFileNew(string nameOfFile, string directoryOfFile, string content) {
   string fileNameToOpen;
   append(fileNameToOpen,".txt");
   FILE *FP = NULL;
   fp = fopen(fileNameToOpen), "r");
   fprintf(fp, content);
   
   fclose(fP); //Close file
   
}

 

Most code I've EVER seriously written, not counting the math header file.

Edited by Kamikaze_Badger

Share this post


Link to post
Share on other sites

/*Sam's DOS Writing Thinger*/
/*Coding assistance provided by:
**Mark C.**/

#include <iostream>
#include <string>
#include <stdio.h> //stdio.h contains the proper library for the function we're using

using namespace std;

string directoryName;
string fileName;
string userEntry;
string password;

char passwordProtect;

string openFileWithDirectory(string,string);
string openFileNew(string,string,string);

int readOrWrite;

int main(void) {
cout << "\n\nWelcome to Sam's DOS Writing Thinger! Would you like to make a new file, or edit an existing one?\n" \
"1: New File\n2:Edit Existing File\n>";
cin >> readOrWrite; /* forgot; here */

switch (readOrWrite) {
 case 1: /* 1: not (1) */ { cout << "\n\nEnter a filename, followed by a .txt: ";
 	cin >> fileName;

 	cout << "\nNow, enter in the words: \n";
 	cin >> userEntry;

 	openFileNew(fileName,directoryName /* wrong variable name here */,userEntry);

 	break;
 }

 default: /* forgot a : here */ { 
 	break; /* int 1; isn't valid syntax, if you really must have something in here maybe try a break; instead :o) */
 } // =D
}

return 0;
}    


string openFileNew(string nameOfFile, string directoryOfFile, string content) {
string fileNameToOpen;
nameOfFile.append(".txt"); /* append if a function of a string object :o) */
FILE *fp = NULL; /* C is case sensitive FP != fp */

fp = fopen(nameOfFile.c_str() /* has to be converted to a C style string */, "w");
fprintf(fp, content.c_str() /* has to be converted to a C style string */);
fclose(fp /* capital P typo? fP != fp */); //Close file
}

 

One thing to think about so far is .txt gets appended to the end, even though you tell the user to stick .txt on the end when typing in the file. You'll end up with, say, blah.txt.txt when the user inputs blah.txt

Share this post


Link to post
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...