Thread: Read string

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    32

    Question Read string

    Hi there,

    I was writing a program to read in a string and print it out in reverse. But for some reason it doesnt compile.The error said

    In function ‘main’:
    error; too few arguments to function ‘tnirp’

    Code:
    #include<stdio.h>
    #include<string.h>
    
    void tnirp(char s[],int max);
    
    int main(int argc, char * argv[]){
            
        char s[100]; 
        
        printf("Enter string\n");
    
        fgets(s,100,stdin);
        
        tnirp(s);
    
        return 0;
    }
    
    void tnirp(char s[],int max){
    
        int i,j;
    
        char rstr[100];
      
       for(i=strlen(s)-1,j=0; i>=0; i--, j++){
    
           rstr[j]=s[i];
    
          }
      
       rstr[j]='\0'; 
    
       printf("%s",rstr);
    
       printf("\n");
     
    }
    I dont know wats going wrong.

    Thanks in advance every1

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > void tnirp(char s[],int max);
    This expects 2

    > tnirp(s);
    This has 1

    What's the issue?
    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
    Registered User
    Join Date
    Apr 2010
    Posts
    32
    Oh i got it .


    Damn it i am such a doushe.



    My corrections


    Code:
    #include<stdio.h>
    #include<string.h>
    
    void tnirp(char s[]);
    
    int main(int argc, char * argv[]){
            
        char s[100]; 
        
        printf("Enter string\n");
    
        fgets(s,100,stdin);
        
        tnirp(s);
    
        return 0;
    }
    
    void tnirp(char s[]){
    
        int i,j;
    
        char rstr[100];
      
       for(i=strlen(s)-1,j=0; i>=0; i--, j++){
    
           rstr[j]=s[i];
    
          }
      
       rstr[j]='\0'; 
    
       printf("%s",rstr);
    
       printf("\n");
     
    }

    thanks salem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my assigment
    By cloverdagreat in forum C Programming
    Replies: 16
    Last Post: 11-21-2009, 12:18 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Replies: 1
    Last Post: 05-30-2003, 02:31 AM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM