Need Help With Sub Procedures

This is a discussion on Need Help With Sub Procedures within the C Programming forums, part of the General Programming Boards category; I need help putting this program I have done that works correctly into Sub procedures. Code: #include<stdio.h> #include<string.h> /* Needed ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    8

    Exclamation Need Help With Sub Procedures

    I need help putting this program I have done that works correctly into Sub procedures.
    Code:
    #include<stdio.h>
    #include<string.h> /* Needed To Do Copy, Reverse & Compare */
    
    int main()
    {
         /* Declare Variables */
         
         char vectorEntered[21]; /* Size = 21 because \0 takes up one space */
         char vectorBackwards[21]; /* Size = 21 because \0 takes up one space */
    
         /* Input From User */
         
         printf("\n Enter A Vector (String):= "); 
         gets(vectorEntered);
    
         /* Changing The Vector, Backwards */
         
         strcpy(vectorBackwards,vectorEntered); /* Copy The Vector Entered to Vector Backwards */
         strrev(vectorBackwards); /* Reverse Vector Backwards */
    
         /* Compare The Vectors And Output Answer */
         
         if(strcmp(vectorEntered,vectorBackwards)==0) /* Compare The Two Variables A Sucess*/
         {
             printf("\n The Vector Entered, \"%s\", is the same forwards as backwards!",vectorEntered);
         }
         else /* Compare The Two Variables Not A Sucess */
         {
             printf("\n The Vector Entered, \"%s\", is not same forwards as backwards!",vectorEntered);
         }
        
        getchar();
        getchar();
        return 0;
    }
    This part below from the program i need in one sub procedure for the input:
    Code:
         printf("\n Enter A Vector (String):= "); 
         gets(vectorEntered);
    I need another for:
    Code:
         strcpy(vectorBackwards,vectorEntered); /* Copy The Vector Entered to Vector Backwards */
         strrev(vectorBackwards); /* Reverse Vector Backwards */
    I also need one for:
    Code:
         if(strcmp(vectorEntered,vectorBackwards)==0) /* Compare The Two Variables A Sucess*/
         {
             printf("\n The Vector Entered, \"%s\", is the same forwards as backwards!",vectorEntered);
         }
         else /* Compare The Two Variables Not A Sucess */
         {
             printf("\n The Vector Entered, \"%s\", is not same forwards as backwards!",vectorEntered);
         }
    Please Help, I dont know how to make sub procdures work properly in this program.

    I have also attached the program as well.
    Attached Files Attached Files

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    If you don't know how to write a function, then I suggest you get a book and Learn C.
    This is not a "Do my assignments for me" forum.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > Assignment3_Question2_JamesByers.cpp (1.1 KB, 1 views)
    Well aside from using gets() at all, you're using a C++ compiler to compile C

    > This part below from the program i need in one sub procedure for the input:
    Call it getInput(vectorEntered)

    > ...
    Say
    CopyAndReverse(vectorBackwards,vectorEntered)

    > ...
    Maybe
    CompareAndPrint(vectorBackwards,vectorEntered)
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
        getchar();
        getchar();
    A better way to do this would be to read http://faq.cprogramming.com/cgi-bin/...&id=1043284392 and come up with
    Code:
    int c;
    while((c = getchar()) != '\n' && c != EOF);
    while((c = getchar()) != '\n' && c != EOF);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use same variable in different procedures?
    By Brigs76 in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2005, 06:37 PM
  2. Linking Fortran procedures with C program
    By gest in forum C Programming
    Replies: 5
    Last Post: 07-14-2003, 01:35 PM
  3. classes and window procedures
    By bennyandthejets in forum Windows Programming
    Replies: 4
    Last Post: 12-25-2002, 07:02 PM
  4. Procedures
    By dustmanx in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 05:49 AM
  5. Class Procedures
    By Marky_Mark in forum C++ Programming
    Replies: 4
    Last Post: 10-27-2001, 06:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21