Thread: am stuck in reading a file

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by abood1190 View Post
    how can i use arrays ... can you give me hints
    Do you not have a textbook you can refer to? These are complex matters not exactly easy to convey in a forum posting. Some extra study would be a good idea at this point... Grab some C programming tutorials from the web and read up...

    In fact... (CLICK HERE)


    For example...
    Code:
    int Docking_ID[10];
    int Max_size[10];
    int Time_Taken[10];
    int Cargs[10];
    
    //....
    
    
      fscanf(file1,"%d %c",&Num_Of_Bays,&Harbour_Name);	
      for (i=0;i<Harbour_Name;i++)
        fscanf(file1,"%d %d %d %f", &Docking_ID[i], &Max_size[i], &Time_Taken[i], &Chargs[i]);
    But there are better ways, the tutorials should help you figure that out.

  2. #17
    Registered User
    Join Date
    Oct 2011
    Posts
    38
    aha thats nice ... do i need to use struct with it ?

  3. #18
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    Quote Originally Posted by quzah View Post
    Code:
    fscanf( file1, " %d %d %d %f", ... );
    Notice the spaces. If you want to read spaces, then add them in your formatting string. The scanf functions expect exactly formatted input, so you have to tell it exactly how the file is set up.
    Quzah.
    Your explained spaces are redundant in this case.
    All numeric scanf-formats 'eats' all heading whitespaces, standard-like, ever.

  4. #19
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by abood1190 View Post
    aha thats nice ... do i need to use struct with it ?
    Did you even bother with the tutorials? Seriously... go do some reading.

  5. #20
    Registered User
    Join Date
    Oct 2011
    Posts
    38
    CommonTater Thank you ,,, i will get back to 2 u asap ........... BillyTKid no more problems with spaces ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck, can't open file
    By cstruggle in forum C Programming
    Replies: 4
    Last Post: 05-12-2011, 02:39 AM
  2. Replies: 16
    Last Post: 01-04-2007, 03:38 PM
  3. Replies: 6
    Last Post: 10-23-2006, 07:22 PM
  4. stuck with file system ....
    By stalker in forum C++ Programming
    Replies: 3
    Last Post: 10-27-2003, 12:28 PM
  5. Newbie - file i/o - I'm stuck
    By djacko in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2002, 09:56 AM