Hello. Im not sure if i am able to create a post just after i got solved another one but i hope so. So here is my qestion. I need to connect somehow those codes.
So it should be something like microsoft notebook. Im not asking for full code, just some hints what am i supposed to do. I have no idea what to do exactly to be hohest
You have 3 main programs, so the first thing to do is change "main" to be a function of another name in 2 of the programs. You need to remove any "main program" junk (I/O that should be a parameter for example, or nonsense I/O like "thanks for using my code") and clean it up.
Then you can build a new main program that calls your functions and has all 3 pieces of code available to use.
#include <iostream>
#include <fstream>
#include <curses.h>
#define MAX_CHARS 4050
usingnamespace std;
/*
void openFile()
{
ofstream file2("text2.txt"); // create and open text file
file2 << "Hello there"; // write in file
file2.close(); // close file
}
*/
void readFile(char text[MAX_CHARS])
{
string line;
ifstream myfile ("MyFile.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) ) // do when true, false only when there are no lines
{
cout << line << endl;
}
myfile.close();
}
else
{
cout << "Unable to open file" << endl;
}
}
void editFile()
{
initscr();
keypad(stdscr, true); //Enable the function key reading mode
noecho(); //Turn off the display of the input characters, you need to getch()
halfdelay(100); //Time limit
printw("Press F2 to exit.\n");
bool ex = false;
while ( !ex )
{
int ch = getch();
switch ( ch )
{
case ERR:
printw("Please, press any key...\n"); //Remind that need to press a button
break;
case KEY_F(2): //exit if f2
ex = true;
break;
default: //if everything is fine, use button code
printw("Code of pressed key is %d\n", ch);
break;
}
refresh(); //show on screen
}
printw("Thank you. Good buy!");
getch();
endwin();
}
void coordinates()
{
initscr(); //curses
//coordinates to x,y
mvprintw( 5, 5, "Hello, World!" );
getch(); //wait for button press
endwin(); //exit from curses
}
int main()
{
char text[MAX_CHARS];
readFile(text);
return 0;
}
Uhm sorry, i got it into 1 program and at least no errors but
1. When i have only "readingFile" in main, i have my text on display line by line
2. When i add "editFile" or "coordinates" after "readingFile" i dont have my text anymore.
I dont really know how to explain but please, look on those screenshots: https://gyazo.com/f19705c5bb5948c8a10811fea6d50545 https://gyazo.com/09f4e909d6d305ad3d92dfe52521ba76