Thread: [Warning] Passing arg 1 of 'reversed' makes integer from pointer without a cast

  1. #1
    Registered User
    Join Date
    Mar 2011

    [Warning] Passing arg 1 of 'reversed' makes integer from pointer without a cast

    I'm not sure what this error means but I know it has something to do with the way I'm passing the string into the function. I'm in my first programming class so forgive me if this is a n00b mistake..

    #include <stdio.h>
    #include <string.h>
    int reversed (char string1, char string2);
    void swap (int* ptrA, int* ptrB);
    int main(){
        char word1[20], word2[20];  
        printf("first word");
        scanf("%s", word1);
        printf("second word");
        scanf("%s", word2);
        if (reversed(word1, word2))
           printf("the strings are opposite");
        else printf("the strings are not opposite");
        system ("PAUSE");
        return 0 
    //Pre: string1 is the name read in from the file. string 2 is the name from the 
    //     customer_type array
    //Post:If string1 is reversed and matches string2 1 is returned, if they don't 
    //     match 0 is returned. 
    int reversed (char string1[], char string2[]) {
         int i, len;
         char temp;
         len = strlen(string1);
         for (i = 0; i < len/2; i++) {
             swap (&string1[i], &string1[len-i-1]);
         if (!strcmp(string1, string2); 
            return 1;
             return 0;
    //Pre: ptrA points to a single character in a string while ptrB points to the 
    //     character equally distant from the center and on the other end of the 
    //     string
    //Post:Swaps the value contained in each of the memoory locations. 
    void swap (int* ptrA, int* ptrB) {
         int temp = *ptrA;
         *ptrA = *ptrB;
         *ptrB = temp;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > int reversed (char string1, char string2);
    does not match
    > int reversed (char string1[], char string2[])
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    note that &string1[i] is pointer to char not pointer to int - this will cause problems with your swap function
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-28-2009, 07:49 AM
  2. Replies: 4
    Last Post: 01-27-2009, 02:33 PM
  3. Replies: 2
    Last Post: 05-21-2008, 02:52 PM
  4. Replies: 17
    Last Post: 02-13-2006, 01:19 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM