Thread: !!_this little chat program..._!!

  1. #1
    Registered User unknownUser's Avatar
    Join Date
    Apr 2002
    Posts
    14

    Unhappy !!_this little chat program..._!!

    My friend and I are creating a chat program, that writes to a txt file and then refreshes the screen... the problem is it deletes the line when someone inputs something...Bad times...Here is the code we have thus far....:

    #include <stdio.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <string.h>
    #include <windows.h>

    char input[1000];
    char name[12];
    int inputFunction();
    int refresh();


    int main ()
    {


    printf("What is your nickname?");
    cin.getline(name, 12);
    return inputFunction();
    }

    int inputFunction()
    {
    printf("\nSpeak: ");
    cin.getline(input, 1000);
    ofstream inputFile ("\\\\AC10-Server\\Students\\AP classes\\io.txt");
    if (inputFile.is_open())
    {
    inputFile << name<<": "<<input;
    //inputFile.close();
    }
    if(strcmp(input, "/exit") == 0)
    {
    return 0;

    }

    if (strcmp(input, "/clear") == 0)
    {
    system("cls");
    }


    //Begin refreshing the damn screen.
    char fileContents[1000];

    ifstream file("\\\\Ac10-server\\Students\\AP classes\\io.txt");

    if(file.is_open()){
    file.getline(fileContents, 1000);
    cout << fileContents << endl;
    }
    else{
    cout << "Unable to open file: \\\\Ac10-server\\Students\\AP classes\\io.txt\n";
    return 0;
    }
    Sleep(1000);

    return inputFunction();
    }


    There we go thanks...

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    15
    ok this is a guess at best but wouldn't u need to increment some type of counter, or "point" the 2nd input to the next slot of the array?

    Say u have ten inputs come in, if they all go the same place they would overwrite one another, but if each one is assigned the next slot of the array, line two, it would add it right?

    I'm a newb don't kill me
    Dude, your getting a dell!

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    >>>Dude, your getting a dell!

    God save us all.
    Blue

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    15
    lmao.

    Its odd man, i'm older but all my freinds tell me i look like, sound like, act like, all that, him. Weird, i won a dell. don't fear i reipped this dell apart from day one, its badass now ; )
    Dude, your getting a dell!

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I would try to help you, if you used the code tags.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Josh, no offense or anything, but get a life. Seriously, not helping a guy (or gal) because s/he didn't use code tags is ridiculous.

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    return inputFunction();

    Not good at all. If the conversation gets long, your stack will fill up quickly. Instead, try using a loop.



    cin.getline(name, 12);

    The array is 12 characters but the null character is automatically added to the end. Hence, someone could screw up their computer by entering a 12 character name.

  8. #8
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Well, if someone wants help, and they know enough to write that code, they should know enough to make it readable. Why should someone try to help another person who doesn't make the slightest effort to try to help people help him?

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    15
    because its nice josh, do u send away everyone u doesn't use a tag?
    Dude, your getting a dell!

  10. #10
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    No, but if the code is that long, you should use the code tags. If it is like 3 or 4 lines then it does not make a difference.

  11. #11
    Registered User unknownUser's Avatar
    Join Date
    Apr 2002
    Posts
    14

    dhurku

    I'm sorry I neglected to use the code tag... SO here...:

    <code>


    #include <stdio.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <string.h>
    #include <windows.h>

    char input[1000];
    char name[12];
    int inputFunction();
    int refresh();


    int main ()
    {


    printf("What is your nickname?");
    cin.getline(name, 12);
    return inputFunction();
    }

    int inputFunction()
    {
    printf("\nSpeak: ");
    cin.getline(input, 1000);
    ofstream inputFile ("\\\\AC10-Server\\Students\\AP classes\\io.txt", ios::app);
    if (inputFile.is_open())
    {
    inputFile << name<<": "<<input;
    inputFile.close();
    }
    if(strcmp(input, "/exit") == 0)
    {
    inputFile <<""<< name<< "Has Exited.";
    return 0;
    }

    if (strcmp(input, "/clear") == 0)
    {
    system("cls");
    }


    //Begin refreshing the damn screen.
    char fileContents[1000];

    ifstream file("\\\\Ac10-server\\Students\\AP classes\\io.txt");

    if(file.is_open()){
    file.getline(fileContents, 1000);
    cout << fileContents << endl;
    file.close();
    }
    else{
    cout << "Unable to open file: \\\\Ac10-server\\Students\\AP classes\\io.txt\n";
    return 0;
    }
    Sleep(1000);

    return inputFunction();
    }

    </code>

  12. #12
    Registered User geekfrog's Avatar
    Join Date
    Apr 2002
    Posts
    14
    code tags are [ code] [/ code] without the spaces. and dont just copy your original code from the first post, that defeats the whole purpose. Copy your original code because the point of code tags are to keep the indents.
    ----------------------------------------
    I'm using Borland C++ compiler v5.5

  13. #13
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Just hit edit on your origional post, and add the code tags. That should work, or you may need to copy it back from your source file so the whitespace is still there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM