Another question....

This is a discussion on Another question.... within the C++ Programming forums, part of the General Programming Boards category; I would like to know if there was any way that I could extend the limits of a char array ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Thumbs up 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

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    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'.
    Last edited by Witch_King; 08-26-2001 at 11:11 PM.
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    Unregistered
    Guest
    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...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21