Thread: HELP with reading files

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    13

    HELP with reading files

    can any1 write a loop for me that will read the entire file
    line by line.. i.e. on each iteration the line with newline charaacter must be stored in a string till the end of file... help..

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    There's just 3 I/O functions you need to use here. fopen(), fclose(), and fgets(). Is your problem in understanding how to use these functions, or how to save the lines you read in with fgets()?

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    13
    Quote Originally Posted by bithub
    There's just 3 I/O functions you need to use here. fopen(), fclose(), and fgets(). Is your problem in understanding how to use these functions, or how to save the lines you read in with fgets()?

    i know these functions .... just i need a working loop...

    ive written 1 but it goes into infinite loop

    written 1 function GetLine(FILE *fp, char *str) .. pass the file pionter and store the line in a string str(gors infinte)..... i know the loop is not that big so kindly if u could wirte the whole loop for m plzplz...(im using Turbo C btw) help appreciated...

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    post your code, and I'll help you out.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    13
    i need to read a file format is ....

    FILE FORMAT

    SYMBOL MNEMONICS OPERANDS

    ..... ......... ........

    [EOF]


    symbols column may not contain a blank...

    no. of blank sapces may not be 1

    i need to read 1 line at a time so that ill have [symbol (1 blank) mnem0nics (1blank) operands] in my string...
    examplefile to be read with smbol)

    loop MOV B,FOUR


    my string should conatain (loop MOV B,FOUR)

    (without smbol)

    DS F10

    string should contain(DS F10) with info that there is no symbol...

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    well, best way to ready a line is using fgets fucntion. google fgets

    HINT: fgets(char *, no of bytes to be read, FILE *);

    ssharish2005

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Again, post your code, and people will help you. We will not do your homework for you.

    http://cboard.cprogramming.com/annou...ouncementid=51

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    13
    thanx a lot guys.. but prblems solved
    actually i had to write a prog to check the syntax of MOV and MVI instruction
    so i had to read the source file that way but now i figured it out how to do it.
    thanx a lot
    i didnt ask ne1 to do my homework .... just needed to know how to read the file the way it was needed... neway thanx for the help...

  9. #9
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    can any1 write a loop for me that will read the entire file
    line by line
    i know the loop is not that big so kindly if u could wirte the whole loop for m plzplz...
    i didnt ask ne1 to do my homework


    i hate to beat a dead horse.. but i think it deserves it..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading User Defined Files
    By Necrofear in forum C++ Programming
    Replies: 17
    Last Post: 06-30-2006, 12:55 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. reading files
    By hiya in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2005, 11:40 AM
  4. A little help reading from files...
    By Invincible in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2002, 10:43 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 07:27 AM