Arithmetic on pointer...?

This is a discussion on Arithmetic on pointer...? within the C Programming forums, part of the General Programming Boards category; When I complie my program I get this error: lab05.c:183: arithmetic on pointer to an incomplete type Line 183 is ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    19

    Arithmetic on pointer...?

    When I complie my program I get this error:

    lab05.c:183: arithmetic on pointer to an incomplete type

    Line 183 is this:

    word[i]=list[x][i];

    I also get it for a few other line similar. I have passed those arrays to the function that contains line 183. They are, however, no different than the orginals other than the i's and x.

    I can post the full code if you perfer... just please help : (

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    post the code, its hard to tell from the little fragment

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    19
    Alright, here it is.

    Code:
    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    #include<string.h>
    
    void menu(int *option);
    void instructions();
    void players(int *player);
    void playGame(char word[], int player);
    void getList(char word[], char list[][], int *count);
    void getWord();
    void enterWord(char word[]);
    void guessWord();
    void drawMan(int numWrong);
    void listWrong(char wrongLetters[], int i, char guess);
    
    
    /*
    *Function: Main
    *
    *Inputs  - 
    *Outputs - 
    *
    *Description:
    *
    */
    main(){
    
            char word[32];
            int option=0, player;
    
            /* Basis number generation on time*/
            srand( (unsigned)time( NULL ) );
    
            system("clear");
    
            printf("***************************************************");
            printf("\n*           Hello!  Welcome to Hangman!           *\n");
            printf("***************************************************");
            menu(&option);
            
            printf("%d", option);
    
            while(option!=4){
              if(option==1)
                playGame(word, player);
              if(option==2)
                players(&player);
              if(option==3)
                instructions();
              menu(&option);
            }
            if(option==4)
              exit(0);
    }
    
    /*
    *Function: Menu
    *
    *Inputs  -
    *Outputs - 
    *
    *Description:
    *
    */
    
    void menu(int *option){
            int choice;
            
            printf("\n\nPlease chose an option:\n\n");
            printf("1.Play Game\n");
            printf("2.Change Players\n");
            printf("3.Instructions\n");
            printf("4.Quit Hangman\n\n");
            printf("Chose option: ");
    
            fflush(stdin);
            scanf("%d", &choice);
    
            switch(choice){
              case 1:
              case 2:
              case 3:
              case 4:
                *option=choice;
                break;
            default:
                while((choice!=1)&&(choice!=2)&&(choice!=3)&&(choice!=4)){
                  printf("That is not a valid entry, try again.\n\n");
                  printf("Chose option: ");
                  fflush(stdin);
                  scanf("%d", &choice);
                }
                *option=choice;
                break;
            }
    }
    
    void playGame(char word[], int player){
    
            int count, fileRead=0;
            char list[100][32];
            
            if(player==1){
              if(fileRead){
                fileRead++;
                getList(word, list, &count);
              }
              getWord(word, list, count);
            }
            else
              enterWord(word);
    
            guessWord(word);
    }
    
    void players(int *player){
    
            int players;
    
            system("clear");
            printf("How many players (1 or 2): ");
            fflush(stdin);
            scanf("%d", players);
    
            *player=players;
    }  
    
    void instructions(){
    
    }
    
    void getList(char word[], char list[][], int *count){
    
            FILE *fp;
            int row;        
    
            if((fp=fopen("words.dat", "r"))==NULL){
              printf("Can't open file.\n");
              exit(0);
            }
            
            for(row=0; (fscanf(fp, "%s", list[row])!=EOF); row++);
            fclose(fp);
    
            *count=row;
    
    }
    
    void getWord(char word[], char list[][], int count){
    
            int x, i, j, usedWords[count], noMore;
            
            noMore=0;
    
            do{     
              x=(rand()%(count));
              noMore++;
            }while((!usedWords[x]==1)&&(noMore<count));
    
            if(noMore==count){
              system("clear");
              printf("\n\n\nYou have beaten HangMan, Congratulations!\n");
              printf("In other words, there are no more words...");
              exit(0);
            }
            
            j=stnlen(list[x]);
            i=0;
    
            while(i < j){
              word[i]=list[x][i];
              i++;
            }
    
            word[j]='\0';
            
            usedWords[x]=1;
    }
     
    void enterWord(word[]){
    
    
    void guessWord(char word[]){
    
            int wordLength, i, j, k, numWrong, numRight, badGuess;
            char blanks[32], wrongLetters[18], guess;
    
            wordLength=strlen(word);
            arrayLength= wordLength + 1;
    
            for(i=0; i<wordLength; i++){
              blanks[i]='-';
            }
    
            blanks[i]='\0';
            numRight=0;
            numWrong=0;
    
            while((numRight<wordlength)&&(numWrong<6)){
              system("clear");
    
              drawMan(numWrong);
              printf("\n\n");
              put(blanks);
              printf("\n                                      ");
              put(wrongLetters);
              printf("\n\nGuess a letter: ");
    
              fflush(stdin);
    
              scanf("%c", &guess);
    
              fflush(stdin);
    
              while((guess<'a')||(guess>'z')){
                printf("Please use lower case letters only.\n\n");
                fflush(stdin);
                printf("Guess a letter: ");
                scanf("%c", &guess);
              }
              
              badGuess=1;
      
              for(j=0; j<wordLength; j++){
                if(word[j]==guess){
                  blanks[j]=word[j];
                  badGuess=0;
                }
              }
    
              if(badGuess){
                numWrong++;
                listWrong(wrongLetters, numWrong, guess)
              }
            
            if(numWrong==6)
              printf("You lose! Sorry!\n");
            else
              printf("You win!  Good job!\n");
    
            printf("Press enter to continue to menu.");
            scanf("%d");   
    }
    
    
    
    void drawMan(int numWrong){
            
            char gallow[7][10]={"/=====o  "
                                "||   |   "
                                "||       "
                                "||       "
                                "||       "
                                "||______ "
                                "|_______\\"};
    
            if(numWrong==1)
              gallow[2][5]='O';
            if(numWrong==2)
              gallow[3][5]='|';
            if(numWrong==3)
              gallow[3][4]='/';
            if(numWrong==4){
              gallow[3][6]='\\';
            }
            if(numWrong==5){
              gallow[4][6]='\\';
            }
            if(numWrong==6)
              gallow[4][4]='/';
    
            puts(gallow[0]);
            puts(gallow[1]);
            puts(gallow[2]);
            puts(gallow[3]);
            puts(gallow[4]);
            puts(gallow[5]);
            puts(gallow[6]);
            puts(gallow[7]);
            
            return(0);      
    }
    void listWrong(char wrongLetters[], int i, char guess){
    
            if(i==1){
              wrongLetters[0]=guess;
              wrongLetters[1]=',';
              wrongLetters[2]=' ';
            }
            if(i==2){
              wrongLetters[3]=guess;
              wrongLetters[4]=',';
              wrongLetters[5]=' ';
            }
            if(i==3){
              wrongLetters[6]=guess;
              wrongLetters[7]=',';
              wrongLetters[8]=' ';
            }
            if(i==4){
              wrongLetters[9]=guess;
              wrongLetters[10]=',';
              wrongLetters[11]=' ';
            }
            if(i==5){
              wrongLetters[12]=guess;
              wrongLetters[13]=',';
              wrongLetters[14]=' ';
            }
            if(i==6){
              wrongLetters[15]=guess;
            }
            wrongLetters[16]='\0';
    }

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Code:
    void getWord(char word[], char list[][], int count){
    Consult your text on how to pass a 'multi-dimensional array' to a function. The way you have it will not work. Basically you can do one of two things:

    Code:
    void getWord(char word[], char list[][32], int count){
    
     /* or */
    
    void getWord(char word[], char *list[32], int count){
    Have a look at your programming text to find out why you can't pass a matrix the way you originally posted it.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    19
    Quote Originally Posted by kermit
    Code:
    void getWord(char word[], char list[][], int count){
    Consult your text on how to pass a 'multi-dimensional array' to a function. The way you have it will not work. Basically you can do one of two things:

    Code:
    void getWord(char word[], char list[][32], int count){
    
     /* or */
    
    void getWord(char word[], char *list[32], int count){
    Have a look at your programming text to find out why you can't pass a matrix the way you originally posted it.
    Alright cool, I'll see if that works : ) Thank you very much.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    19

    Infinite scanf o O?

    Has anyone else had a problem where the scanf would just keep prompting? This is odd... really odd.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You should really actually pay attention to your compiler. Here's a few points:
    Code:
    fflush(stdin);
    You don't flush a faucet, you flush a toilet. In other words, what you're doing is undefined behaviour, and is not guarinteed to work by the standard. Read the FAQ on the topic of flushing the input stream for more.
    Code:
    printf("Press enter to continue to menu.");
            scanf("%d");
    What exactly is this supposed to do? Consider reading the FAQ sections on getting your program to wait for a keystroke. Or actually make that read something. Oh yeah, and pay attention to your compiler.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Read the FAQ on the topic of flushing the input stream for more.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351

    Consider reading the FAQ sections on getting your program to wait for a keystroke.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Pointers, arithmetic, and order of operation.
    By Aerie in forum C Programming
    Replies: 4
    Last Post: 04-19-2005, 07:35 AM
  4. Replies: 41
    Last Post: 07-04-2004, 03:23 PM
  5. pointer arithmetic with characters
    By VanJay011379 in forum C++ Programming
    Replies: 6
    Last Post: 07-21-2002, 01:50 PM

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