Thread: [help!!!!]fscanf question

  1. #1
    Registered User
    Join Date
    Jan 2008

    [help!!!!]fscanf question

    Hi there!

    I'm doring material computer simulation and encounter a problem. Whenever I run the simulation. It would dump files named after with timestep. For example, my dump files are Al.1000, Al.2000, Al.3000 and etc. 1000,2000 and 3000 are timesteps. These files have same pattern and different values. My supervisor require me to write a C program, extracting the information of a certain line of all the dump files (around 2000 files) and record the values in another file. My dump file format is shown below:

    0 20.225 I need this line's information
    0 20.225
    0 20.225
    1 0 0 0
    2 4.045 0 0
    3 8.09 0 0
    6 2.0225 2.0225 0
    7 6.0675 2.0225 0
    11 0 4.045 0
    12 4.045 4.045 0
    13 8.09 4.045 0

    So, can someone tell me that how to write a program to extract the information I need, which I listed above? Also, how to loop from one file to another, just like loop from Al.1000 to Al.2000 and to Al.3000. Thanks a lot !!!!!!!!!!!!!!!
    Last edited by Salem; 01-17-2008 at 12:09 AM. Reason: Less extreme font size

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Is your supervisor requiring you to write a program in C because he wants you to learn the C language, or because he doesn't know shell scripting?

    You could do this in C. You would have to know what all the file extensions are, and which line you need. Is it always the one after "ITEM: BOX BOUNDS"? Always the sixth line of the file? Always the first one with two numbers?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Yes, you can automatically find all the files [at least, as long as they follow a certain pattern] - just like with what tabstop says, you need to know EXACTLY how the filenames are formatted - is it always 4 digits, or is it "as many digits as you need".

    You can use sprintf() to form the filename, but you need to understand HOW to form it to match what the program that creates the files does.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM
Website Security Test