-
Another question....
I would like to know if there was any way that I could extend the limits of a char array (or whatever it is called) beyond 256 (or whatever the limit is) so I would be able to make some sort of cheap version of a word processor and save it to a file. And also, how would I be able to enable the user to create their own title. Here is my code to help you...
#include <iostream>
#include <fstream>
using namespace std;
main()
{
ofstream output;
output.open("file.txt");
char text[256];
cin.getline(text,256);
output << text;
output.close();
int var1, var2, var3, var4;
}
As you can see, the file name is automaticly specified as "file.txt". And "text" is set to a limit of 255 characters. Some guy on this board wrote code similar to this and he included the line :
"int var1, var2, var3, var4;" in it. Is this really necessary for the program to work?
I know it's alot of questions, but I am only 13 (14 in two weeks from tommorrow) and I am still learning.
Thanks
-Chris
-
The input buffer will only allow the user to enter 255 characters at a time but this only applies to console applications. In order to overcome this you would have to use a Windows application.
In 'C', you can ask for user input and open a file like this:
Code:
char sFilename[30];
printf("Enter the file name: ");
gets(sFilename);
FILE *fptr = fopen(sFilename,"r"); if(fptr == NULL) exit(1);
In C++ you would do something similar with cout and cin. Once you have the user input stored in a string you can apply the array it in the function rather than using hard code such as 'file.txt'.
-
That is not the way to do a text editor...
You actually need to be a bit more cunning than that...
My advice is to store each line as a node in a linked list, that way you can render the page easily and it is easy to save it, just traverse the list and save the nodes...