Thread: FILES question

  1. #1
    Registered User
    Join Date
    Sep 2009

    FILES question

    Question 8:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void main(){
    char data[ __ 1 __ ], tel[__ 2 __];
    FILE *fptr;
    int flag;
    fptr = fopen("stam.txt","r");
    while ((flag = fscanf(fptr, "% __ 3 __ [^$]% __ 4 __ %*c", data, tel)) == __ 5 __){
      printf("%s,%s\n", data,tel);        
    }  assume, that the data of ‘Bezek’ client is stored in one line in the file, as followed:
    # Name – 20 characters.
    # Address – 20 characters.
    # Id number – 9 digits.
    # Phone number – 9 digits. 
    complete the missing, seperate your answer with , (comma) your answer should look like 12,32,10,2,2
    in your answer do not use unnecessary spaces, you must not spend unnecessary memory
    write the SHORTEST answer, (use %s instead of if possible !!!
    Assume data include : Name, Address & ID.

    this is mt ans: 50s,10,49,10,3 , why this is not true ?

    TNX .....

  2. #2
    Registered User
    Join Date
    Sep 2006
    First thing to do is print out the values of each of your variables, right after you get them from the file. Are they coming into your program, OK?

    Then sprinkle a couple printf() statements around the program, so you can check if the data is still good, at that line of the program.

    You have to work on your troubleshooting skills, and this is a nice short program. Your ==__5__ on the end of the fscanf() function, looks very dodgy, but I don't understand the % being used with all those formatting codes.

    I usually work it the other way around. i get more data, put it into a buffer if I need to parse it heavily, and then use sscanf(), etc., on it, from there, to get what I need.

    I never liked the scanf() functions, much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick question on reading files in C
    By TaiL in forum C Programming
    Replies: 12
    Last Post: 10-05-2008, 09:48 PM
  2. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  3. input/output files question
    By ssjnamek in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2005, 12:38 PM
  4. Question about ".o" files
    By Jez_Master in forum C++ Programming
    Replies: 1
    Last Post: 04-11-2002, 01:54 AM
  5. Using files: Wacked Question
    By Denethor2000 in forum C++ Programming
    Replies: 2
    Last Post: 04-06-2002, 12:54 AM