Like Tree1Likes
  • 1 Post By GReaper

fscanf at "dynamic" matrix

This is a discussion on fscanf at "dynamic" matrix within the C Programming forums, part of the General Programming Boards category; hi everyone.. im rookie at programming and i have got a question.. i ve got this txt file.: i want ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    Chios, Greece, Greece
    Posts
    2

    fscanf at "dynamic" matrix

    hi everyone.. im rookie at programming and i have got a question..
    i ve got this txt file.:
    i want to read all this file and print it. the problem is that the number of collumns isnt standard, but depends from n (the 1st number of this file )
    as i said im new at programming and i cant find a solution for this problem..


    PS..
    i know that one of the rule of the forum is to not answer to this kind of question by givving all the code but ... i havent any hope to find a solution.....
    Attached Files Attached Files

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Quote Originally Posted by jimbakl View Post
    i know that one of the rule of the forum is to not answer to this kind of question by givving all the code but ... i havent any hope to find a solution.....
    Of course you do! Get a damm book about C and start reading, or read the tutorials of this site.

    PS: Go to a greek forum. Most idiots there hand over the code to you without question. ( Σόρρυ )
    Billaros likes this.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Oct 2011
    Location
    Chios, Greece, Greece
    Posts
    2
    sorry countryman

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,276

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    6		                       //comment  example, n=6 it could be 10 or 2, show the number of clients
    0 200 80 140 100 75                   // is a matrix with n+1 rows and n collumns 
    0 26.9 50.2 49.3 46.3 12	
    26.9 0 72.4 74.7 68.7 70.4
    50.2 72.4 0 54.7 4 75
    49.3 74.7 54.7 0 52.2 25.2
    46.3 68.7 4 52.2 0 71.7
    12 70.4 75 25.2 71.7 0
    Start by looking at your file... What do you see?


    Ok first line is a single integer which happens to be 6
    After that every line has how many numbers?

    So the first line tells you what?

    Can you figure out from the file how big your array needs to be?
    Can you figure frome the file what kind of values it contains?
    Can you figure out from the file how you might read in the values?

    What choices do you have for storing this array?

    Hint: Look for simple answers... this one isn't hard.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Well the first step is to try and write the code based on the assumption of a small value of n

    Say
    double matrix[10][10];

    Can you write the code to read a file into such a matrix?

    If you can't then there are some basic things to sort out long before we get to the "dynamic" part of the problem.

    Don't worry, the code you write for the fixed array will still work with a dynamic array, so you're not going to waste a lot of time on code you won't use.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf "%as" (dynamic char arrays)
    By brightmatter in forum C Programming
    Replies: 10
    Last Post: 03-05-2010, 11:05 PM
  2. Using operator "()" inside boost matrix
    By jutirain in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2008, 12:19 AM
  3. Why does the program terminate at "fscanf" function?
    By Mathsniper in forum C Programming
    Replies: 3
    Last Post: 05-22-2006, 11:23 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21