urlencode in C

Discussion in 'C Programming' started by Rudra Banerjee, Oct 11, 2012.

  1. Hello,
    Can you people kindly show me how to encode a url search string in C?
    What I meant is something like this:

    $ python
    Python 2.7.3 (default, Jul 24 2012, 10:05:38)
    [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from urllib import urlencode
    >>> myDict={

    .... "Name":"Albert Einstein",
    .... "Year":"1905"
    .... }
    >>> s=urlencode(myDict)
    >>> print s

    Name=Albert+Einstein&Year=1905

    I want to achieve the same effect in C.
     
    Rudra Banerjee, Oct 11, 2012
    #1
    1. Advertising

  2. Rudra Banerjee

    Paul Guest

    Rudra Banerjee wrote:
    > Hello,
    > Can you people kindly show me how to encode a url search string in C?
    > What I meant is something like this:
    >
    > $ python
    > Python 2.7.3 (default, Jul 24 2012, 10:05:38)
    > [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.
    >>>> from urllib import urlencode
    >>>> myDict={

    > ... "Name":"Albert Einstein",
    > ... "Year":"1905"
    > ... }
    >>>> s=urlencode(myDict)
    >>>> print s

    > Name=Albert+Einstein&Year=1905
    >
    > I want to achieve the same effect in C.


    http://stackoverflow.com/questions/2525518/writing-code-translator-from-python-to-c

    Maybe give this one a try. Perhaps it can translate
    a short code segment, in a useful way. And show you
    a possible solution.

    http://code.google.com/p/shedskin/

    Paul
     
    Paul, Oct 11, 2012
    #2
    1. Advertising

  3. Rudra Banerjee

    Mark Bluemel Guest

    On 11/10/2012 22:47, Rudra Banerjee wrote:
    > Hello,
    > Can you people kindly show me how to encode a url search string in C?
    > What I meant is something like this:
    >
    > $ python
    > Python 2.7.3 (default, Jul 24 2012, 10:05:38)
    > [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.
    >>>> from urllib import urlencode
    >>>> myDict={

    > ... "Name":"Albert Einstein",
    > ... "Year":"1905"
    > ... }
    >>>> s=urlencode(myDict)
    >>>> print s

    > Name=Albert+Einstein&Year=1905
    >
    > I want to achieve the same effect in C.


    I'm not going to write an example for you. If this is the coursework it
    looks like, I think your tutor would rather you wrote your own code.

    The process seems to be fairly simple string manipulation, with rules
    something like this :-

    For each name/value pair
    Remove double quotes
    Replace embedded spaces with '+'
    Concatenate names and values separated by '='
    Concatenate successive name/value pairs separated by '&'

    If you use this set of rules, it should be fairly simple to write the
    code, depending on how much parsing of your input data is needed.

    Try it, and if you have problems post your code together with some
    representative input data for us to review.
     
    Mark Bluemel, Oct 12, 2012
    #3
  4. Rudra Banerjee

    Mark Bluemel Guest

    On 12/10/2012 08:09, Mark Bluemel wrote:
    > On 11/10/2012 22:47, Rudra Banerjee wrote:
    >> Hello,
    >> Can you people kindly show me how to encode a url search string in C?
    >> What I meant is something like this:
    >>
    >> $ python
    >> Python 2.7.3 (default, Jul 24 2012, 10:05:38)
    >> [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
    >> Type "help", "copyright", "credits" or "license" for more information.
    >>>>> from urllib import urlencode
    >>>>> myDict={

    >> ... "Name":"Albert Einstein",
    >> ... "Year":"1905"
    >> ... }
    >>>>> s=urlencode(myDict)
    >>>>> print s

    >> Name=Albert+Einstein&Year=1905
    >>
    >> I want to achieve the same effect in C.

    >
    > I'm not going to write an example for you. If this is the coursework it
    > looks like, I think your tutor would rather you wrote your own code.
    >
    > The process seems to be fairly simple string manipulation, with rules
    > something like this :-
    >
    > For each name/value pair
    > Remove double quotes
    > Replace embedded spaces with '+'
    > Concatenate names and values separated by '='
    > Concatenate successive name/value pairs separated by '&'
    >
    > If you use this set of rules, it should be fairly simple to write the
    > code, depending on how much parsing of your input data is needed.
    >
    > Try it, and if you have problems post your code together with some
    > representative input data for us to review.
    >

    See http://en.wikipedia.org/wiki/Percent-encoding for more detailed
    discussion of urlencoding and the additional processing of certain
    characters.
     
    Mark Bluemel, Oct 12, 2012
    #4
  5. On 2012-10-11, Rudra Banerjee <> wrote:
    > Hello,
    > Can you people kindly show me how to encode a url search string in C?
    > What I meant is something like this:
    >
    > I want to achieve the same effect in C.


    http://andrews.freeshell.org/urldec.tar

    --
    Andrew Smallshaw
     
    Andrew Smallshaw, Oct 12, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ

    URLEncode

    Russ, Aug 4, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,933
    mikeb
    Aug 4, 2003
  2. vtreddy

    Datagrid HYperlinnk column URLEncode

    vtreddy, Oct 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    396
    vtreddy
    Oct 24, 2003
  3. vtreddy

    URLEncode Problem from ASP.NET

    vtreddy, Oct 25, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    5,693
    vtreddy
    Oct 25, 2003
  4. Andreas Klemt
    Replies:
    4
    Views:
    10,302
    mikeb
    Jan 22, 2004
  5. Dario Sala
    Replies:
    1
    Views:
    3,805
    Karl Seguin
    Nov 15, 2004
Loading...

Share This Page