need help?? ...reading input data

This is a discussion on need help?? ...reading input data within the C++ Programming forums, part of the General Programming Boards category; HI! I have been struggling with this for the past couple of days, could someone PLEASE help? I need to ...

  1. #1
    smd is offline
    Registered User
    Join Date
    Jun 2002

    need help?? ...reading input data


    I have been struggling with this for the past couple of days, could someone PLEASE help?

    I need to read in a file (I have no problems doing this), however while there are certain numbers I have to bring in and store into a variable: ( I have attached a sample data file and my program is below along with where I am confused)...

    so when the file is being read in it need to look for 3 things, including "/Scan Size: " , when it sees it, it needs to be able to read the number that has been assigned to it and store it in a variable. So in the sample data file, when it sees "\Scan Size: " it needs to read in 2678.88, and the other 2 are the "\Z sensitivity: " and "\Z max: "

    also, my compiler(codewarrior) does not allow for a direct delaration of strings, instead as an array of characters....

    I have my program below and have attached my data file...

    I really will appreciate any help any one can give...thanks in advance

    #include <stdio.h>
    #include <string.h>
    #include <cstring>

    int main(){

    ifstream infile("data2.txt");
    ofstream outfile("output.txt");

    char buffer1 [256];
    char c;

    //this compiler, codewarrior, does not allow string declarations,
    //they have to be declared as an array of characters

    //these are the 3 things to be looking for
    char Scansize[12] = "\Scan Size: ";
    char Zsen[16] = "\Z sensitivity: ";
    char Zmax[8] = "\Z max: ";

    if (infile.is_open()){

    while (infile.good())
    while(!infile.eof()) //need to read till reaches EOF
    c = infile.get();

    if (strncmp (c, "\Scan Size: ", 12)==0); //??not sure how to use strncmp here, because it is an array of chars not a string??
    //??not sure how to bring in the number assigned to it
    //then infile>>scansize;


    } } }


    return 0;


    thanks for any help...
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  2. Please Help Reading Data From A File
    By NickHolmes in forum C Programming
    Replies: 5
    Last Post: 05-29-2005, 11:24 PM
  3. Reading input from a data file
    By prefect115 in forum C Programming
    Replies: 3
    Last Post: 09-26-2004, 12:30 PM
  4. Message printing problem
    By robert_sun in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 05:05 AM
  5. Problem with Printing message
    By robert_sun in forum C Programming
    Replies: 2
    Last Post: 05-16-2004, 02:09 PM

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