GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-May-2008, 11:53
rags rags is offline
New Member
 
Join Date: May 2008
Posts: 3
rags is on a distinguished road

urgent help needed with cross word program to find all d words in it


Hi all!!

i m doing a dummy project ...pls help me out in it

given an MxN filled up cross word,write a prog to print all the words present in it.
Cross word table is given as input in a text file that contains ‘0’ for a shaded square and any other valid alphabet [A-Z] for any other position. Each row is a line of text input. A word has to be at least 2 letters long. The program has to read in the input file, and then print out all the words present.
The program has to print the output in the following format :

< i j > : < word > : < across / down >
eg output: <1,6>:Republic:Across
<2,3>:Independence:down

pls do help me out with this...

thx in advance
  #2  
Old 13-May-2008, 12:21
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,200
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: urgent help needed with cross word program to find all d words in it


Quote:
Originally Posted by rags
i m doing ...

From Guidelines for posting requests for help

1: When asking questions about code you need to post some code. We cannot help you if you show us nothing you've attempted. Posting just your assignment/problem description is likely to get a few snide comments and nothing more. You've also wasted at least half a day while someone decides to post a message asking what you've done. Save time -- post code.

I won't make any snide comments (I'll leave that to others), but I would like to emphasize that we can't possibly know what kind of help you would like to get. We have no way of knowing what you know and/or what you have done.

Are there any specific areas of the assignment that are confusing to you? Where would you like to start?

Regards,

Dave
  #3  
Old 13-May-2008, 12:26
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: urgent help needed with cross word program to find all d words in it


here is an algorithm, but definitely not the best algorithm.
Code:
# pseudocode from index i range: 0..N from index j range: 0..M skip if grid [ i : j ] is '0' check grid [ i : j ] going right until '0' # that is, increase j until grid [ i : j ] is '0' print origin, word, 'across' check grid [ i : j ] going down until '0' # that is, increase i until grid [ i : j ] is '0' print origin, word, 'down' loop j loop i
Work with that and post back with what you get. We will help you from there.
  #4  
Old 14-May-2008, 11:45
rags rags is offline
New Member
 
Join Date: May 2008
Posts: 3
rags is on a distinguished road

Re: urgent help needed with cross word program to find all d words in it


CPP / C++ / C Code:
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
 
#define MAX 80
 
int main(int argc, char*argv[])
{
    FILE *fp;
    char str[MAX];
    char names[MAX][MAX];
    int row = 0, col = 0;
 
    fp = fopen(argv[1], "r");
    if (fp == NULL)
    {
        printf("File opening failed\n");
        return 0;
    }
 
    int i=0, j=0;
    char ch;
    while(1)
    {
        ch = getc(fp);
        if(ch == EOF)
        {
            break;
        }
        names[i][j] = ch;
        j++;
        col++;
        if(ch == '\n')
        {
            row++;
            i++;
            j = 0;
        }
        //printf("char in file reading %c" , ch);
    }    
 
    col = col/row;
    printf("row is %d col is %d", row, col);
    for(i = 0; i<row; i++)
    {
        printf("names is %s\n",names[i]);
        for(j =0; j<col; j++)
        {
            if(names[i][j] == '\n')
            {
                names[i][j]='\0';
            }
        }
    }
 
    int m = 0;
    int pos1, pos2;
    str[m] = '\0';
 
    for(i = 0; i<row; i++)
    {
        //printf("names is %s\n",names[i]);
        for(j =0; j<col; j++)
        {
            if(names[i][j] != '0')
            {
                pos1 = i;
                pos2 = j;
                while(isalpha(names[i][j]))
                {
                    str[m] = names[i][j];
                    j++;
                    m++;
                }
                str[m] = '\0';
                m =0;
                if(strlen(str) >= 2)
                {
                    printf("<%d, %d> : %s : across \n", pos1+1, pos2+1, str);
                }
            }
        }
    }
 
    printf(".........................................................................\n");
    m = 0;
    pos1, pos2;
    str[m] = '\0';
    for(j = 0; j<col; j++)
    {
        //printf("names is %s\n",names[i]);
        for(i =0; i<row; i++)
        {
            if(names[i][j] != '0')
            {
                pos1 = i;
                pos2 = j;
                while(isalpha(names[i][j]))
                {
                    str[m] = names[i][j];
                    i++;
                    m++;
                }
                str[m] = '\0';
                m =0;
                if(strlen(str) >= 2)
                {
                    printf("<%d , %d> : %s : down \n", pos1+1, pos2+1, str);
                }
            }
        }
    }
 
    fclose(fp);
    return 0;
}
Last edited by admin II : 14-May-2008 at 18:22. Reason: Please surround your C code with [cpp] your code [/cpp]
  #5  
Old 14-May-2008, 11:47
rags rags is offline
New Member
 
Join Date: May 2008
Posts: 3
rags is on a distinguished road

Re: urgent help needed with cross word program to find all d words in it


This is whtt i've done so far...
but this is printing me all d words thtt are across and then printing all those words which are down in d crossword table...

i need 2 get it like arcoos n its assosiated then n so on...
  #6  
Old 14-May-2008, 12:31
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 785
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: urgent help needed with cross word program to find all d words in it


Could you also post your sample file? Then we could compare apples to apples.
Also , , , enclose your code in the C++ tags , , , Then spaces will work for indentation in your posting, Thanks.
 
 

Recent GIDBlogReview: Gel laptop cooling pad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help with my C program to find Pi values mccrbr01 C Programming Language 1 30-Oct-2004 23:47
C Currency Conversion program help needed mutt C Programming Language 1 13-Jun-2004 16:14
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 21:06
urgent help needed :c + mysql insert jack C Programming Language 1 13-Apr-2004 22:16

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.