Thread: filing

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    27

    filing

    hey guys !! i have been given an assignment and i dont know how to get started .. the question is :
    You will be given two files.

    Grid.txt will contain a grid of letters (as shown below)j q v r l k u v e r s i o n l
    d v k e r n e l t u m e d i a
    i e c k s n d y v x k d n w e
    r k u c w g e c b a l z u s j
    r p h a l d a t a o t w h x d
    q x p h d s i f w m a c a p a
    w d p b d q f r t o z r r o o
    p a o m o u s e f n r l d t l
    r t l s c a a t c i b k w p n
    o a i u u p z n j t l z a a w
    g b a v m b n i z o x e r l o
    r a m g e e a r n r j g e q d
    a s e w n y c p y c v b b t z
    m e q d t n s e q j f g v x b
    v x i n i v b o i p v v t j b

    Words.txt: containing a list of words as shown below.
    data database document download email file hacker hardware kernel keyboard laptop media monitor mouse network printer program scan undo version
    You have to write a program which find all the words given in Words.txt from the gird given in Grid.txt. The words can be in any direction - horizontal, vertical or diagonal. It should write a new file Output.txt which writes a modified grid such that letters not in any word are replaced by blanks. (See example below)
    - - - r - k - v e r s i o n -
    - - k e r n e l - - m e d i a
    - - - k - n - y - - - - n - -
    - - - c - - e - b - - - u - -
    - - - a - d a t a o - - h - d
    - - - h - - - - w m a - a p a
    - d - - d - - r - o - r r o o
    p a - m o u s e f n r - d t l
    r t l - c - - t - i - k w p n
    o a i - u - - n - t l - a a w
    g b a - m - n i - o - e r l o
    r a m - e - a r - r - - e - d
    a s e - n - c p - - - - - - -
    m e - - t - s - - - - - - - -
    - - - - - - - - - - - - - - -

    Your code should work for a grid of any size and a word list of any size as well (Use dynamic memory allocation, static arrays are not allowed; wasting memory is not allowed). Your program should be able to figure out the size of the grid by reading the file (No user input!)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A development process
    I guess the first thing you do is write a program which reads ONE of the files.

    Then enhance it by reading the other file.

    Finally, you solve the puzzle.
    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.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    27
    Quote Originally Posted by Salem View Post
    A development process
    I guess the first thing you do is write a program which reads ONE of the files.

    Then enhance it by reading the other file.

    Finally, you solve the puzzle.
    how do i keep track of the rows and columns ?? it says that your program should be able to read the size of the grid ..

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > how do i keep track of the rows and columns ?? it says that your program should be able to read the size of the grid ..
    If you started with
    char grid[100][100];
    would you know how to read grid.txt ?

    Because turning a fixed size char grid[100][100]; into a fully dynamic char **grid is fairly simple, once you've got the code working.

    The lesson isn't how to build the whole program in one edit session, it's about learning how to break the program down into a number of achievable steps.
    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.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Salem View Post
    char grid[100][100];
    Better is to use std::string for reading the lines and if you need to remember lines, then a dynamic array (eg std::vector) would be a good idea.
    If you don't have the logic down, experiment with a flowchart.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A little problem with filing in C
    By TheUmer in forum C Programming
    Replies: 19
    Last Post: 03-22-2010, 11:33 AM
  2. how to make a program using Filing in C++?
    By zedora in forum C++ Programming
    Replies: 1
    Last Post: 01-14-2010, 11:24 AM
  3. filing problems..urgent...
    By must in forum C++ Programming
    Replies: 0
    Last Post: 07-23-2002, 04:31 AM