Thread: How To Embed Data In Program While Compile?

  1. #1
    Registered User
    Join Date
    Jan 2002

    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
    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
    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)"C:MrA\\1.txt");
    else if(strcmp(name, "MrB") == 0)"C:MrB\\1.txt");
    else if(strcmp(name, "MrC") == 0)"C:MrB\\1.txt");

    char data[80];
    infile >> data;

    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, 03:30 PM
  2. Replies: 1
    Last Post: 12-30-2007, 10: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, 04:03 PM
  5. Replies: 2
    Last Post: 11-10-2003, 09:12 PM