0

Hi guys, im new to these forums and would like some help with two problems im having in my program to make crossword
The crossword requires me to read 5 inputs in one line.
word row column direction clue

Problem 1- input
I wish to getchar the first word

while((answerInput[count][i++]=getchar())!=' ' && i<SIZE);


                    answerInput[count][i]='\0';




                    /*TO SCAN FOR THE WORD, HOW TO TERMINATE AT SPACE..THIS INCLUDES SPACE*/

Problem 2 - equating arrays
Im having trouble storing the word 2d array into the board 2d array

   int i;
   int j;

   int rowInputInt = (int)rowInput[count];
     if (direction[count]=='d')
     { 
          j=columnInput[count];

          for(i=rowInputInt;i<rowInputInt+strlen(answerInput[count]);i++)
         {  
               board[i][j]=answerInput[count][i];
         }
     }

     /*This not storing into array...so when i print the board 
       nothing happens at moment*/

Can you guys please tell me how to fix this. Im pretty new to C.

2
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by rover100
0

K i think i fixed problem 2
replacing the loop to be

if (direction[count]=='d')
     { 
          j=columnInput[count];
          for(i=rowInputInt,k=0;i<rowInputInt+strlen(answerInput[count])&&k<strlen(answerInput[count]); k++,i++)
         {  
               board[i][j]=answerInput[count][k];
         }
     }

//it displays on board :D. But still white space placed on board from first issue

0

Can someone help me fix this. I need to exit if they type only '.' in the total field. How do i exit if they type this

              /*if (getchar()!='.')
              {
              answerInput[count][0]=m;                              
              */  
               while((answerInput[count][i++]=getchar())!=' ' && i<SIZE)
               {
                    if(answerInput[count][i]=='.')
                    {
                         printf("ERROR");
                    }     
               }          

                    answerInput[count][--i]='\0';

//Its not exiting
0
if(answerInput[count][i]=='.')
{
    printf("ERROR");
    break;
} 

or something like that is possible bot i didnt tested just a sketch

//read 
char c = getchar();
while(c!='.' && i<SIZE)
{
    answerInput[count][i++] = c;
c = getchar();// get next char then
}
answerInput[count][--i]='\0';

Edited by Sokurenko: more code

0

Thanks, altered a little but concept works well

int i=0;             
          char c=getchar();

          if(c=='.')                              
          {
               printf("ERROR");

          }     
          while((c!=' ' && i<SIZE))
          {                                            //ANSWERINPUT
               answerInput[1][i++]=c;
               c=getchar();
          }                    
          answerInput[1][i]='\0';                 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.