Simple C assignment, need help!

This is a discussion on Simple C assignment, need help! within the C Programming forums, part of the General Programming Boards category; So i need help on a simple assignment. The assignment is: ** HW5 ** You have been hired to so ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Simple C assignment, need help!

    So i need help on a simple assignment.

    The assignment is:

    ** HW5 **

    You have been hired to so some data processing. The directory "datafiles"
    contains 1100 files of data that were captured by a SETI research
    organization. Unfortunately some of the data files were mysteriously
    damaged. You have been asked to write a shell script that will find the
    damaged files.

    All of the files are supposed to contain 16 lines of data. Some of the files
    have fewer lines, some have more. Your script should go through all of the
    files in the directory and print out just the ones that do not have exactly 16
    lines in them.

    For each defective file print only the file name. That is, after your script
    runs you should see a listing of just the filenames of the defective files.

    *NOTE: you need to use a for loop to do this. The following solution will not
    be acceptable:

    Code:
     wc -l * | grep -v 16 | awk '{ print $2 }'
    Neither will any other solution that doesn't use a loop to iterate over all of
    the files.

    Also note that this is an easy way to loop over all of the files.

    ------
    for f in `ls`
    do
    Code:
    echo $f
    done
    ------


    PS: This is for a UNIX basic's class. The teacher did not implement ANY C programing until these last two weeks. One of which i missed because i was snowed in.

    So i am very confused any help would be greatly appreciated!

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    I forgot to mention this needs to be written in C.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Start by writing a C program that checks if a given file is valid.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Start by writing a C program that checks if a given file is valid.
    I guess i should say i am completely ignorant to programing. I have no idea where to begin.

    None of the C programing we will be doing is on the test. It is all covering UNIX commands and the basics.

    Thank you for the advise, but i wouldnt know where to begin...

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So your bit of a shell script should be directing it's output into you C program as stdin, I take it?

    Code:
    for f in `ls`
    do
      echo $f
    done
    
    
    //so maybe something like:
    for f in `ls`
    do
      yourCprogram <echo $f
      //gives your program one filename via main(int argc, char *argv[])
      //counts up the lines of data in the file
      //print out the filename if it doesn't have 16 lines
    done
    Does this look about right? I could do it with a DOS/Windows bat file, but I've never worked with Unix.

    Have you thought about what the C program should have in it, yet? If so, post up whatever you have, and kick start this thing.

    This is an example of how I did it recently, in Windows, with a bat file:
    Code:
    @echo off
    echo ****************************
    echo Welcome to solver1.bat
    echo Starting bb_sudoku_v05c.exe
    echo ****************************
    for %%a in (Q*.*) do call solver2 %%a
    echo.
    echo Done!
    
    /* the above found looped through every file that began with Q 
    and passed the files name, to solver2.bat, which was this:
    
    */
    echo Now processing file: %1
    bb_sudoku_v06.exe -T0 -S2 -P <%1> out
    echo.
    echo Searching for "- Solved"
    find "- Solved" out >> Gold16.txt
    del /Q %1
    echo %1 file has been deleted.
    This was all geared for a Sudoku project, but the same
    idea: Use a shell script to feed input to your C program,
    (in my case bb_sudoku_v06.exe), and have it work
    on every file whose name was given to it, from the < pipe.
    Last edited by Adak; 12-06-2010 at 12:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 03:50 PM
  2. simple chat program questions
    By surefire in forum C Programming
    Replies: 5
    Last Post: 11-05-2009, 07:16 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple question about array of chars
    By Chewy in forum C Programming
    Replies: 9
    Last Post: 04-12-2004, 05:13 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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