#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Help: warning: value computed is not used


    My program reads in a text file which has a word search in it and solves it.

    This is a plan C programing and I'm using a linux box compiling using: gcc -Wall -std=c99 -pedantic FILENAME.c -o FILENAME

    run using ./FILENAME.c <data >Solution

    Getting a warning:
    warning: value computed is not used [-Wunused-value]
    on lines 63,64,65,66.

    Also I my copyPuzzle function is not working.
    It looks like it should work, but my program always
    prints off a blank solution like it never copies the answers
    to the PuzzleOut array.

    Code:
    #include <stdio.h>
    #include <string.h>
    #define SIZE 50
    
    int getSize(char Puzzle[][SIZE]);
    void setPuzzle(char Puzzle[][SIZE],int Length);
    void copyPuzzle(char Puzzle[][SIZE], char Word[SIZE], int Row, int Col, int RD, int CD);
    int search(char Puzzle[][SIZE], char Word[SIZE], int *Row, int *Col, int *RD, int *CD,int Length);
    int printPuzzle(char Puzzle[][SIZE],int Length);
    
    int main(){
        char PuzzleIn[SIZE][SIZE] = {{0}};
        char PuzzleOut[SIZE][SIZE] = {{0}};
        char Word[SIZE+2];
        int Length = 0,Row = 0,Col = 0,RD = -1,CD = -1;
    
        Length = getSize(PuzzleIn);
        setPuzzle(PuzzleIn,Length);
    
        while(fgets(Word,sizeof(Word),stdin)){
            if (search(PuzzleIn,Word,&Row,&Col,&RD,&CD,Length))
                copyPuzzle(PuzzleOut,Word,Row,Col,RD,CD);
        }
    
        printPuzzle(PuzzleOut,Length);
    }
    
    int getSize(char Puzzle[][SIZE]){
        char Line[SIZE*2+2];
        int Size = 0,Row = 0,Col;
    
        fgets(Line,sizeof(Line),stdin);
            Size = (strlen(Line)-1)/2;
        for(Row = 0;Row < Size; Row++){
            for(Col = 0; Col < Size;Col++)
                Puzzle[Row][Col] = Line[Col*2];
        }
        
        return(Size);
    }
    
    void setPuzzle(char Puzzle[][SIZE],int Length){
        int Row,Col;
    
        for(Row = 1;Row < Length;Row++){
           for(Col = 0; Col < Length+1;Col++){
               char Temp = getchar();
    
                if(Temp == '\n'){
                    break;
                }
                else{
                    Puzzle[Row][Col] = Temp;
                    (void)getchar();
                }
            }
        }
    }
    
    int search(char Puzzle[][SIZE], char Word[SIZE+2], int *Row, int *Col, int *RD, int *CD, int Length){
       int Check = 0, I = 0;
    
        for(*Row = 0;*Row < Length; *Row++) {   
            for(*Col = 0;*Col < Length; *Col++) {
                for(*RD = -1;*RD < 2; *RD++) {
                    for(*CD = -1;*CD < 2; *CD++) {
    
                        if(*RD || *CD){
                            Check = strlen(Word);
                            for(I = 0;I < Check; I++){
                                if (Word[I] == Puzzle[*Row][*Col]){
                                    *Row += *RD;
                                    *Col += *CD;
                                }
                            }
                        }
                        else{
                            printf("\nWord not found:%c\n",Puzzle[*Row][*Col]);
                            return(0);
                        }
                    
                        if(I == Check){
                            return (1);
                        }
                    }
                }
            }
        }   
        return(0);
    }
    
    void copyPuzzle(char Puzzle[][SIZE], char Word[SIZE+2], int Row, int Col, int RD, int CD){
        int copyCount = strlen(Word);
        int I;
        
        for (I = 0; I < copyCount; I++){
            Puzzle[Row][Col] = Word[I];
            Row += RD;
            Col += CD;
        }
    
    }
    
    int printPuzzle(char Puzzle[][SIZE],int Length){
        int Row=0,Col=0;
        
        for(Row = 0;Row < Length+1; Row++){
            for(Col = 0; Col < Length+1; Col++){
                char Temp = Puzzle[Row][Col];
    
                if(Temp == 0){
                    break;
                }
                else{
                    printf("%c", Puzzle[Row][Col]);
                }
            }
            printf("\n");
        }
        return(0);
    }
    This is the input I'm currently using its a text file.
    Code:
    S D N O M L A N O W H I O T O 
    P E P A S P A R A G U S H P P 
    I O M K R E T T A E O E E I P 
    N C H I C K E N A C R A G U S 
    R N C S L R E B M U C U C T O 
    U O A H M L B O Y H R A A H Y 
    T I P E C A T T L E M O N S B 
    T N L E T D N N G N N K G A E 
    R O G P I S T A C H I O R B A 
    N H R E B N B L N N R L H T N 
    B S C R B B O P G A E A U O S 
    C I L R A G W G N Y B N B L A 
    R D E C R C H G N O L U A I H 
    B A C O F F E E R A R T R V P 
    E R A E P S A A W U M A B E R 
    CATTLE
    PIG
    SHEEP
    CHICKEN
    HONEYBEES
    RICE
    BARLEY
    OATS
    SOYBEANS
    SUGARCANE
    ONION
    PEACH
    PEAR
    WATERMELON
    ORANGES
    LIMES
    LEMONS
    BANANA
    OLIVE
    ALMOND
    APRICOT
    ASPARAGUS
    RABBIT
    BEET
    CABBAGE
    CARROT
    COFFEE
    CUCUMBER
    EGGPLANT
    GARLIC
    MANGO
    KOLANUT
    PISTACHIO
    RADISH
    RHUBARB
    TURNIP
    TEA
    WALNUT
    How output should look, I'm not having much luck here.
    All the letters that do not belong to words need to show
    as blank spaces.

    Code:
    S D N O M L A     W           
    P E   A S P A R A G U S   P P 
    I   M   R E T T         E I   
    N C H I C K E N A C R A G U S 
    R N C S L R E B M U C U C T O 
    U O A H M   B   Y H     A   Y 
    T I   E C A T T L E M O N S B 
    T N L E T   N N G   N K   A E 
      O   P I S T A C H I O R   A 
    N H R E B   B L N   R L H T N 
      S C R B B O P   A E A U O S 
    C I L R A G   G N Y B N B L   
    R D   C R C   G N   L U A I   
      A C O F F E E   A   T R V   
      R A E P S     W   M   B E

    All help is appreciated thanks!!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    In your search function you willy-nilly modify *Row and *Col in your inner loop. These values aren't magically restored to the prior nice loop counter values by omniscience.

    That, and I'm also not seeing any reason for these counters to simply walk out of the array to access memory you didn't intend for them to access.

    Also, move Check = strlen(Word) out of the inner loops. Move it out of all the loops. Something like this (except you'll need to declare more row and column variables):
    Code:
    int search(char Puzzle[][SIZE], char Word[SIZE+2], int *Row, int *Col, int *RD, int *CD, int Length) {
      int Check = strlen(Word), I = 0;
    I didn't look at your puzzle copier, I'd bet it works.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    156
    Rep Power
    33
    *pointer++ is the same as *(pointer++). My guess is you want (*pointer)++

IMN logo majestic logo threadwatch logo seochat tools logo