Thread: how to write a pseiudocode ?

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    24

    how to write a pseiudocode ?

    i write a c program of a phone book.now i writing the pseudocode for the program.
    i added a search function under delete function book phone book.so user can search a phone number and then delete it.
    so want to know how to write a pseudocode for that part?

    what is the way to join these search and delete functions?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You can put functions and function calls in pseudocode.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    24
    Quote Originally Posted by MK27 View Post
    You can put functions and function calls in pseudocode.
    can you plz give me a small example about that?i didn't get it.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is your code? You can just distill the C specific parts to become Python, I mean pseudocode.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Maybe it would be easier if you posted some of the pseudcode you already have. AFAIK, there's no standard for it, so you can write how ever you like.

    Quote Originally Posted by laserlight View Post
    What is your code? You can just distill the C specific parts to become Python, I mean pseudocode.
    @blogchama: this is actually a good point, google some python and look eg.
    Code:
    if 1:
            for i in range(5):
                    print i
    Last edited by MK27; 01-22-2010 at 01:11 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    As MK27 said, there's no real "definition" or "standard" for pseudocode. I like to think of it as "English" with "invalid programming language code" (i.e. code that would probably produce an error, if taken verbatim). I'll try and write a small example of reversing a string.

    Code:
    char* reverse(char * str, int len)
    {
      int i;
      for ( i := 0; i < len/2; i++)
      {
        char temp = str[i];
        str[i] = str[len - i];
        str[len - i] = temp;
      }
      
      return str;
    }
    Code:
    algorithm: reverse
    input: 'str', string to reverse
    output: the reversed string
    -----------------------------------
    begin
      let len := length of str
      for i := 1 to len/2
        swap characters in str at positions i and (len-i)
      end
    end
    Of course its possible there are logic errors in either segments above, as I have quickly typed it up. If so, do not waste your time telling me, if you do then you are missing the point.

    Also, sometimes the actual code is almost identical to the pseudocode (say in a factorial function), and so you can hardly distinguish between them. Of course it is still "valid" pseudocode, though. One key thing I'd like to make is that in pseudocode, if you want to use some "function" that is intuitive enough to understand (i.e. "swap"ping two characters), you just use it without defining it.

    Again, keep in mind, there is no real format or standard to follow. You asked for an example, I gave you one.
    Last edited by nadroj; 01-22-2010 at 02:13 PM.

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    24
    Quote Originally Posted by nadroj View Post
    As MK27 said, there's no real "definition" or "standard" for pseudocode. I like to think of it as "English" with "invalid programming language code" (i.e. code that would probably produce an error, if taken verbatim). I'll try and write a small example of reversing a string.

    Code:
    char* reverse(char * str, int len)
    {
      int i;
      for ( i := 0; i < len/2; i++)
      {
        char temp = str[i];
        str[i] = str[len - i];
        str[len - i] = temp;
      }
      
      return str;
    }
    Code:
    algorithm: reverse
    input: 'str', string to reverse
    output: the reversed string
    -----------------------------------
    begin
      let len := length of str
      for i := 1 to len/2
        swap characters in str at positions i and (len-i)
      end
    end
    Of course its possible there are logic errors in either segments above, as I have quickly typed it up. If so, do not waste your time telling me, if you do then you are missing the point.

    Also, sometimes the actual code is almost identical to the pseudocode (say in a factorial function), and so you can hardly distinguish between them. Of course it is still "valid" pseudocode, though. One key thing I'd like to make is that in pseudocode, if you want to use some "function" that is intuitive enough to understand (i.e. "swap"ping two characters), you just use it without defining it.

    Again, keep in mind, there is no real format or standard to follow. You asked for an example, I gave you one.

    thank all of you friends for your valuable advices.
    i want to know are there any softwares to convert a source code to a pseudocode?
    i

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You're going the wrong way.

    You should be starting with pseudo-code and ending up with code (not the reverse).

    For what it's worth, your detailed pseudo code would be the comments in your real code.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-18-2006, 11:25 AM
  2. program to make a floppy write protected
    By shrijeetp in forum C Programming
    Replies: 1
    Last Post: 10-03-2005, 06:00 AM
  3. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 04:48 PM
  4. Function to write string 3 times
    By Giggs in forum C++ Programming
    Replies: 15
    Last Post: 12-24-2002, 04:00 PM
  5. write in c
    By PutoAmo in forum C Programming
    Replies: 6
    Last Post: 04-03-2002, 07:53 PM