Error with the string.h header

I get this error when I try to compile following C program

#include <stdio.h>
#include <strings.h>

#define LEN    80

int main(void)
{
    int mess[LEN],  flag = 1;
    int first = 0, last = 0;
    
    printf("Enter a message: ");
    gets(mess);
    
    if (strlen(mess) > LEN)
    {
        printf("Out of memory\n");
        return 2;
    }
    else 
        last = strlen(mess) - 1;
        
    while (first <= last)
    {
        if ( mess[first] != mess[last] )
        {
            flag = 0;
        }
        
        first++;
        last--;
    }
    
    if (flag == 1)
    {
        printf("Message is palindrom\n");
    }
    else 
        printf("Message isn't palindorm\n");
    
    return 0;
}

When I run source through lint then I get following messages.

$ cc 2a.c -o 2a                                                    
"2a.c", line 23: warning: argument #1 is incompatible with prototype:
    prototype: pointer to char : "/usr/include/iso/stdio_iso.h", line 226
    argument : pointer to int
"2a.c", line 25: warning: argument #1 is incompatible with prototype:
    prototype: pointer to const char : "/usr/include/iso/string_iso.h", line 63
    argument : pointer to int
"2a.c", line 31: warning: argument #1 is incompatible with prototype:
    prototype: pointer to const char : "/usr/include/iso/string_iso.h", line 63
    argument : pointer to int

Thanks for helping :smiley:

Hi solaris_user,

I think those are not errors. Can you look if the executable was created?

You could avoid them declaring the mess variable as an array of chars.

char mess[LEN];
int first = 0, last = 0, flag = 1;

Regards,
Birei

1 Like

Thanks for your reply, it was silly mistake. I have problems with same program but rewritten to use pointer instead array indexing.

#include <stdio.h>
#include <strings.h>

#define LEN 80 

int main(void)
{
     char mess[LEN], *p, *q;
     int flag = 1;
     
     printf("===== Palidnrom Pointer Checker ============== \n");
     printf("Copyright 2012 (c) \n");
     printf("Compiled successfully on date %s \n", __DATE__);

     printf("\nEnter a message up to %d charachters: ", LEN);
     
     for (p = &mess[0]; p < &mess[LEN]; p++)
     {
         *p = getchar();
         if (*p == '\n')
         {
             break;
         }
     }
     
     q = &mess[ strlen(mess) -1 ];
     
     while (p <= q)
     {
         if (*p != *q)
         {
             flag = 0;
         }
         p++;
         q--;
     }
     
    if (flag == 1)
    {
        printf("Message is palindrom\n");
    }
    else 
        printf("Message isn't palindorm\n");

     
     return 0;
 }

Program alway throws me the same message, no matter what input is :stuck_out_tongue:

$ ./2b                           
===== Palidnrom Pointer Checker ============== 
Copyright 2012 (c) 
Compiled successfully on date Jan 10 2012 

Enter a message up to 80 charachters: ada
Message isn't palindorm

answer should be that input message is palindrom.

I think, you should not include strings.h but string.h (without the s).