problem: function should have a prototype

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iqbalbd
    New Member
    • Jan 2013
    • 1

    problem: function should have a prototype

    I have a problem. function should have a proto type. any body help me..
    Code:
    #include<stdio.h>
    #include<string.h>
      main()
    {
    
    
    	char arr[10];
    	printf("Enter a string to reverse\n");
    
           gets(arr);
    
    	streev(arr);
    
           printf("Reverse of entered string is \n%s\n",arr);
    
           return 0;
    }
    Last edited by acoder; Jan 21 '13, 08:15 AM. Reason: Added text from title to post
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    line 12, should be strrev instead of streev.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      This didn't cause the error message, but line 3 should be:
      Code:
      int main(void)

      Comment

      • swapnali143
        New Member
        • Mar 2012
        • 34

        #4
        Here function to reverse string is strrev()
        and u used streev() which is not defined in libraries of c

        Syntax of strrev() is

        strrev(string);
        Correct code is as follows
        Code:
            #include<stdio.h>
            #include<string.h>
              main()
            {
             
             
                char arr[10];
                printf("Enter a string to reverse\n");
             
                   gets(arr);
             
                strrev(arr);
             
                   printf("Reverse of entered string is \n%s\n",arr);
             
                   return 0;
            }

        Comment

        • Anas Mosaad
          New Member
          • Jan 2013
          • 185

          #5
          That's what I said earlier.

          @donbock, not sure if your statement is correct. I remember from our C class (more than a decade from now) that we could have a main without an int return type.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            @Anas Mosaad quite a few C/C++ courses around the world seem to teach that main can return void. The problem is 2 fold

            a. They are using an old non-standard compiler that kind of supports this return type.

            b. They are wrong. The C/C++ standards* prohibits a return type from main other than int.


            * Strictly speaking the C++ standard prohibits a return type from main other than int. The C standard allows a return type other than int (normally void) but this is considered a compiler extension and as such is completely non-portable.

            In general it is a good idea to avoid compiler extensions if at all possible as you never know when you may need to use a different compiler and you can't be sure it will have the same extensions.

            Comment

            • Anas Mosaad
              New Member
              • Jan 2013
              • 185

              #7
              I agree @Banfa with your post. However I keep my words that the statement should never give such an error as @donbock was trying to says in his post!

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                As I said, your "function should have a prototype" error message has nothing to do with your main declaration.

                Refer to the C FAQ:

                Comment

                • Anas Mosaad
                  New Member
                  • Jan 2013
                  • 185

                  #9
                  @donbock, I'm not a native English speaker but I think your post #3 is the opposite of #8. I'm not trying to argue you but I'm trying to make sure I understand it well.
                  You said "This didn't cause the error message, but line 3 should be:". I believe this means that #2 didn't cause the error and the error is should be at line 3. Is this what your statement says? or I misunderstood it?

                  Comment

                  • donbock
                    Recognized Expert Top Contributor
                    • Mar 2008
                    • 2427

                    #10
                    What I meant in post 3 was that nothing I was about to say about the proper declaration of main() had anything to do with the error message you reported in your original post.

                    Comment

                    • Anas Mosaad
                      New Member
                      • Jan 2013
                      • 185

                      #11
                      I misunderstood that statement. Anyway, thanks for the clarification :-)

                      Comment

                      Working...