How To Embed Data In Program While Compile?

This is a discussion on How To Embed Data In Program While Compile? within the C++ Programming forums, part of the General Programming Boards category; I want to ask like this below example? Example : If there are 3 people , all of them have ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    How To Embed Data In Program While Compile?

    I want to ask like this below example?
    Example :
    If there are 3 people , all of them have text file name 1.txt.

    If Mr. A has data X in text file like this
    X = POIR
    Mr. B has data X in text file like this
    X = JUKFDSSA
    Mr. C has data X in text file like this
    X = OYTGF

    I want to embed this data in program while compile.
    Example: If I use text file of Mr.A I will have data X = POIR after compile program. If I use text file of Mr.B I will have data X = JUKFDSSA after compileprogram.

    If my program is in directory C:\ .
    Where I need to put 1.txt file and how to write program to do that .

    Thank you.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I would use three separate files, like this:

    C:MrA\1.txt //data for MrA wihich is POIR
    C:MrB\1.txt //data for MrB which is JUKFDSSA
    C:MrC\1.txt //data for MrC which is OYTGF


    and then in your program do something like this:

    iostream infile:
    char name;
    cout << "enter your name" << endl;
    cin >> name;

    if(strcmp(name, "MrA") == 0)
    infile.open("C:MrA\\1.txt");
    else if(strcmp(name, "MrB") == 0)
    infile.open("C:MrB\\1.txt");
    else if(strcmp(name, "MrC") == 0)
    infile.open("C:MrB\\1.txt");

    char data[80];
    infile >> data;
    //etc.

    now data will contain the first string in the associated file.

    if you're not familiar with strcmp() say so.

    BTW: you wouldn't need three separate files to achieve the same effect, but it sounds like that's what you want to do, so so be it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Replies: 1
    Last Post: 12-30-2007, 09:08 AM
  3. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  4. How to complete program. Any probs now?
    By stehigs321 in forum C Programming
    Replies: 7
    Last Post: 11-19-2003, 03:03 PM
  5. Replies: 2
    Last Post: 11-10-2003, 08:12 PM

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