Thread: enter in a window & store it in a file

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    enter in a window & store it in a file

    hi guys,

    this code is working fine in taking entries from user and storing it in a file.. but my requirement is the request must be in a window of the specified size and the entry should also be taken in the window itself.. which inturn should get stored in the text file.

    also if anybody would suggest me how would i specify the path for the file to be created.

    #include <stdio.h>
    #include <conio.h>

    int main(void)
    {
    char buffer[BUFSIZ] = {127};
    FILE *pFile;
    char *p;
    clrscr();
    window(10,10,70,20);

    pFile = fopen ("myfile.txt","wt");
    if (pFile!=NULL)
    {
    cprintf("Enter a string \r\n");
    p = cgets(buffer);
    fputs(p,pFile);
    fclose(pFile);
    }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    strange..

    aaye the same code worked very well in turbo c.. I am able to enter the text in the window and the result is stored in text file..

    could anybody explain and help me out in Borland C++.. i m still trying to get it right myself..

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    OS is Win2K and compiler is Borland C++ 5.5

  4. #4
    Registered User angeljicu's Avatar
    Join Date
    Nov 2002
    Posts
    16

    Maybe I could help you....

    Hum.........
    you have forgot to add something
    {
    .....
    char buffer[BUFSIZ] = {127};
    FILE *pFile;
    char *p;
    clrscr();
    window(10,10,70,20);

    pFile = fopen ("c:\\myfile.txt","wt");
    if (pFile!=NULL)
    {
    cprintf("Enter a string \r\n");
    p = cgets(buffer);
    fputs(p,pFile);
    }
    fclose(pFile);
    return 0;
    }
    path is "c:\\..\\.."
    c:\\myfile.txt
    there is angel,who love to see u.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Maybe I could help you....

    Originally posted by angeljicu
    Hum.........
    you have forgot to add something

    |----- snip -----|

    path is "c:\\..\\.."
    c:\\myfile.txt
    No, actually you don't have to specify a path. If you don't, it assumes you mean the directory where the program iteself is running from.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    yaa, the whole program goes like this.. so this code will make a file in the O drive.

    but still can anybody explain me the whole code.. specially the sequence in which file is made and the parameters specified..

    Code:
    #include <stdio.h>
    int main ()
    {
      char p[BUFSIZ] = {127};
      FILE *pFile;
      pFile = fopen ("o:\\myfile.txt","wt");
    
      if (pFile!=NULL)
      {
        printf("Enter your text :");
        gets(p);
        fputs (p,pFile);
        fclose (pFile);
      }
     return 0;
    }
    Last edited by vivek_kumbhar; 11-03-2002 at 12:39 AM.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by vivek_kumbhar
    but still can anybody explain me the whole code.. specially the sequence in which file is made and the parameters specified..
    First up:
    >>char p[BUFSIZ] = {127};
    In your program, there's no need for the 127. This will get overwritten by the gets() function. Which leads me nicely into the point at which I tell you not to use gets(), lookup fgets() instead.

    >>pFile = fopen ("o:\\myfile.txt","wt");
    Here the file is opened for writing in text mode (wt), but the 't' attribute is non standard, and there compiler dependant.


    A summary of the programs function is:
    - Open a file
    - If the File Open worked:
    - - Read a line of data from the keyboard
    - - Write that line to the file
    - - Close the file

    Does this help?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM