urlencode in C

R

Rudra Banerjee

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..... "Name":"Albert Einstein",
.... "Year":"1905"
.... }Name=Albert+Einstein&Year=1905

I want to achieve the same effect in C.
 
P

Paul

Rudra said:
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.... "Name":"Albert Einstein",
... "Year":"1905"
... }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
 
M

Mark Bluemel

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.... "Name":"Albert Einstein",
... "Year":"1905"
... }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.
 
M

Mark Bluemel

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top