Thread: need help reading a file (isbn program)

  1. #1
    Registered User
    Join Date
    Oct 2007

    need help reading a file (isbn program)

    Hopefully you'll know what an "isbn" is (International Standard Book Number). Well i have to make a program that gives me the area, publisher and tittle number from a valid isbn number.
    the isbn number: 0003194876 is valid and the area number is: 0, publisher is: 00 and title is 319487 and the number six in the isbn number is the check digit.

    so one isbn number is split into 4 seperate ones. I have to use a file that is basically a list of valid area and publisher numbers. the first column is the list of area numbers valid and the second is minimum number in that specific publisher range while the other is maximum

    File text link
    the first rown has
    0 00 19
    0 is the area, 00 is min for publisher and 19 is max

    Basically i have to check the first number in a isbn string see if its in the list on the first column when i find a area that works i check for the publisher...if i don't find a area for the first digit i check the first and second and so on until i find.

    int decode(FILE* fp, const char* str, char* area, char* publisher, char* title){
        while (!feof(fp)) {
              fscanf(fp, "%s %s %s\n", c, d, e);
        return 0;
    ^^ this is the function im going to use, so far i just have a fscanf working

    What i need is some advice on how to start it, like how can i save the first character in "str" and check if their is a valid area number for that digit.

  2. #2
    The larch
    Join Date
    May 2006
    Perhaps it was easier if you read your input into int variables instead?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > while (!feof(fp))
    Read the FAQ

    > fscanf(fp, "%s %s %s\n", c, d, e);
    Use fgets() to read a whole line of what one would presume to be an ISBN, then validate it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Why isn't my program reading my file properly?
    By DCMann2 in forum C Programming
    Replies: 10
    Last Post: 04-23-2008, 01:16 AM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Whats wrong with my file reading program?
    By Alphabird32 in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2002, 03:19 AM