Thread: Reading length of string from record in file

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    44

    Reading length of string from record in file

    I am writing a program that creates a textfile that stores records. Each record is storing the following structure :

    Code:
    typedef struct Client
    {
            char id[10];
            char name[25];
            char surname[25];
            
    } Client;
    I need to create a function that checks the string length of the 'id' of structure for a given record number RecNum by the user.

    If the string length is equal to 0 , it means that the record is available for booking , and the program must return the word 'Free' , else it must return the word 'Taken'.

    Can someone help me please?

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Post the code you've got, and explain where you're stuck.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Google strcmp() and strlen().
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    44
    I need to know how to access the character string from the file according t the RecNumber inputted by the user , s that I can read the length using strlen().

  5. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You can't access only parts of a file. You have to read it whole, put it in some sensible data structures and then find whatever it is you are looking for in it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-17-2011, 03:51 AM
  2. Replies: 1
    Last Post: 07-10-2006, 06:30 AM
  3. Replies: 20
    Last Post: 06-12-2005, 11:53 PM
  4. Reading a record from a File
    By David101 in forum C Programming
    Replies: 2
    Last Post: 12-14-2004, 06:42 PM
  5. reading a customer record file
    By abbycat131 in forum C++ Programming
    Replies: 1
    Last Post: 01-29-2003, 09:15 PM