Error with the string.h header


 
Thread Tools Search this Thread
Top Forums Programming Error with the string.h header
# 1  
Old 01-09-2012
Error with the string.h header

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

Code:
#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.

Code:
$ 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 Smilie
# 2  
Old 01-09-2012
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.
Code:
char mess[LEN];
int first = 0, last = 0, flag = 1;

Regards,
Birei
This User Gave Thanks to birei For This Post:
# 3  
Old 01-10-2012
Thanks for your reply, it was silly mistake. I have problems with same program but rewritten to use pointer instead array indexing.

Code:
#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 Smilie

Code:
$ ./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.
# 4  
Old 01-10-2012
I think, you should not include strings.h but string.h (without the s).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

awk to skip header row and add string to field

The awk below does put in VUS in the 9th field but I can not seem to skip the header then add the VUS. I tried to incorporate NR >=2 and NR > 1 with no luck. Thank you :). input Chr Start End Ref Alt Func.refGene PopFreqMax CLINSIG Classification chr1 43395635 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

4. Shell Programming and Scripting

Need awk help to print specific columns with as string in a header

awk experts, I have a big file of 4000 columns with header. Would like to print the columns with string value of "Commands" in header. File has "," separator. This file is on ESX host with Bash. Thanks, Arv (21 Replies)
Discussion started by: arv_cds
21 Replies

5. Shell Programming and Scripting

Extract columns where header matches a given string

Hi, I'm having trouble pulling out columns where the headers match a file of key ID's I'm interested in and was looking for some help. file1.txt I Name 34 56 84 350 790 1215 1919 7606 9420 file2.txt I Name 1 1 2 2 3 3 ... 34 34... 56 56... 84 84... 350 350... M 1 A A A A... (20 Replies)
Discussion started by: flotsam
20 Replies

6. Shell Programming and Scripting

Renaming all header to specific header pattern

Input #HAC0253 EFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #BASFS12 EFVEFVHIJEFVEFVTOPKEFVOPKTHIJTTHIJOPK #ACG5115 TEFVEFVOIJEFVHIJHIJOPKOPKHIJHIJTTEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK #ECG5114 IJTOPKHIJEFVOEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK . . Output (5 Replies)
Discussion started by: patrick87
5 Replies

7. Shell Programming and Scripting

Inserting a String in a file header.

Dear all, I have a file created in the name sample.txt in UNIX with header and footer. How to insert a required string (for example "FILE1") in the header part after the file has been created. What kind of command can i use to do the same. Thanks in advance Hari (3 Replies)
Discussion started by: Hari123
3 Replies

8. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies

9. UNIX for Dummies Questions & Answers

Checking the header and trailer for a given string and if not found, exit out of the

hi, How to check a given file for a string and if it's not found, exit out ofthe script? e.g. a file Test123 is there whose header begins with #bt and trailer begins with #ed. I have to check if the header and trailer matches as above and if not, exit out of the script. How can we do it in... (2 Replies)
Discussion started by: er_ashu
2 Replies

10. Shell Programming and Scripting

Count string at header.

Hi there, it may quite easy but i've tried my best to editing this awk script but didn't get to solution. Scripts:BEGIN { Header = "1 "; FileType = "NBI"; #Count = Count + 1; printf("%-2s%-3s%03s%-14s%-84s\r\n", Header, FileType, Count, FileSeq, SysTime, " "); } { ... (13 Replies)
Discussion started by: Helmi
13 Replies
Login or Register to Ask a Question