Thread: int from pointer without a cast warning.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    int from pointer without a cast warning.

    Hi, i'm getting several warnings and erros upon adding a function to my program and I am not entirely sure as to what they are, any ideas?


    Code:
    #include <stdio.h>
    
    #include <string.h>
    
    #include <stdlib.h>
    
    #include <math.h>
    
    
    int wordcount( char words[])
    
    {
    
     int  j=0 , wcnt = 0, lenght;
    
    
    
    j=strlen(words)-1;
    
    while( strchr(" \t", words[j]) != 0 ) { words[j]=0 ; j-- ; }
    
    
    
    j=0 ;
    
    
    while( strchr(" \t", words[j]) != 0 ) j++;
    
    words=words+j;
    
    
    
    lenght = strlen(words) ;
    
     for(j=0; j<=lenght; j++ ) 
    
         if( strchr(" \t", words[j]) != 0 ) {
         while( words[j+1]==' ' || words[j+1]=='\t' ) j++ ; wcnt++ ; }
    
    /* At the EOF strchr() returns as if it matched ! */
    
    
    
     return(wcnt);
    
    }
    
    
    
    
    
    
    
    
    
    
    
    int sylcount( char * words )
    
    {
    
     int i , j , sylc=0, length=strlen(words);
    
     char * vowels="AEIOUYaeiouy";
    
    
    
     for(j=0 ; j<=length ; j++){
    
         i=j;
    
         while( j<= length && strchr(vowels, words[j]) != 0 ) j++ ;
    
               if( 1<j-i ){ sylc++ ; i=j; }
    
    }
    
     return(sylc);
    
    }
    
    
    
    
    
    int sentencecount( char * sentence)
    
    {
    
     int  j , sencnt = 0, lenght = strlen(sentence);
    
     char *sentenders = ".;:?!" ;
    
    
    
     for(j=0; j<=lenght; j++ ) 
    
         if( strchr(sentenders, sentence[j]) != 0 ) sencnt++;
    
    
    
    /* At the EOF strchr() returns as if it matched ! */
    
    
    
     return(sencnt);
    
    }
    
    
    
    int indexcalc(int wcnt, int sylc, int sencnt)
    {
     int IDX;
    
    IDX = 206.835 - 84.6 * (sylc/wcnt) - 1.015 * (wcnt/sncnt);
    
    return(IDX);
    }
    
    
    
     
    
    int main()
    
    {
    
    
    
    char buf[1048576] , * i , * j ;
    
    
    
    i=buf;
    
    
    
    while( fgets(i, 1048576, stdin) != 0 )
    
      {
    
        if ( ( j=strchr(i,'\n') ) != 0 ) *j=' ';
    
        i=i+strlen(i);
    
      }
    
    
    
    printf("\n\n%s\n\n", buf);
    
    
    
    
    
    printf("Index is: %d\n", indexcalc(buf));
    
    printf("Number of words: %d\n", wordcount(buf));
    
    printf("Number of sylables: %d\n", sylcount(buf));
    
    printf("Number of sentences: %d\n", sentencecount(buf));
    
    
    
    
    
    }

    a2.c: In function ‘main’:
    a2.c:86: warning: passing argument 1 of ‘indexcalc’ makes integer from pointer without a cast
    a2.c:58: note: expected ‘int’ but argument is of type ‘char *’
    a2.c:86: error: too few arguments to function ‘indexcalc’

    Any help would be appreciated, i've been playing with this for 3 days now.

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Edit: not sure about the "note: expected ‘int’ but argument is of type ‘char *’". Need to format your code a little better. There are a lot of implicit casts in there from char to int, as strchr expects a const char * and an int, respectively.

    Code:
    printf("Index is: %d\n", indexcalc(buf));
    indexcalc takes 3 arguments
    Last edited by Epy; 02-12-2010 at 12:08 PM.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The warning doesn't make much sense - but it's probably because of a side effect of your error: you've defined indexCalc to accept three integers, but you pass it a (char *). As a side note, I see you doing lots of division and work with decimals with ints - remember that an int will drop the fractional part of any number (though maybe that's what you want - just thought I'd bring it your attention).

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Post deleted, sean beat me to all points
    Last edited by Epy; 02-12-2010 at 12:14 PM. Reason: sean beat me to it

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by sean View Post
    The warning doesn't make much sense - but it's probably because of a side effect of your error: you've defined indexCalc to accept three integers, but you pass it a (char *).
    Actually the warning does make sense, and it is as you say related to the error.
    Argument 1 of indexCalc is expecting an int but he is passing a char*, and like the warning says the pointer is being converted in to an integer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 06:02 AM
  2. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM