![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
I've been trying to figure this one out for a while and my brain is fried. Basically, Im trying to write a function that will remove the "%20" thats represents a space in html and relace it with "\ ". Im trying this using the strstr() function, but I really dont know how to start this, or what I need for a basic algorithm. Any thoughts or ideas would be greatly appreciated, or even just a point in the starting direction.
THANKS! Scrag |
|
|
|
|
|
#2 |
|
Newbie
|
Sounds like a fun function. One question and then I would LOVE to help you. Will you be reading an external file or is the user going to be inputing the text into the command line? I might still be able to help if it is with the external file, that just makes things a tad harder. Only because I have not done much with external files, and so I don't have the most experience.
__________________
<span style='color:green'>Some people are afraid of the net. I'm afraid of what's outside it.</span> |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4
![]() |
It would be easy with an external file...Just use fgets and read one line at a time
![]()
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
I am writing a web server, I got the web server part pretty much done, but Im adding the ability for the web server to list a directory for downloading files if needed. This will be a function that will be passed a string variable. For example, it gets passed the http string "Cool%20File.mpg", then I need to replace the http space "%20" with "\ " so the unix file system can read the file/cd to the dir. So after the function gets passed the string "Cool%20File.mpg", it should return the string "Cool\ File.mpg"
Thanks for the help!! ![]() |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
If you're writing a webserver than you need to do more than convert just %20. You have to convert every number that appears after a % to its hexadecimal -> character value. Not just 20 for space..
__________________
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Dec 2004
Posts: 3
Rep Power: 0
![]() |
Don't know what platform u're writing the program in but there is a function in msdn that does this for you ::: InternetCanonicalizeUrl
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
Yeah, i knoiw I need to convert all number values, but I figured this would be a good start
I am using C and compiling with gcc, under linux. Im think in gonna write the function to read each char of the string to a new buffer string, then when strstr(httpGET_PATH, "%20), wite out a `\` and a ' ' char, skip 3 chars, continue etc. Any suggestions on a better way would be cool.Thanks again, Scrag |
|
|
|
|
|
#8 |
|
Programming Guru
![]() |
There may or may not be a better way to do the if evals... but heres code for %20 that could be easily adapted....
void convertURL(char *blah) {
char url[1024]; // If you have URLs bigger than 1024, you have problems...
strcpy(url, blah);
for(int len=0;len<1024;len++) if(url[len] == NULL) break;
char newStr[1024];
int pos = 0;
for(int i=0;i<len - 3;i++) {
if(url[i] == '%' &&
url[i+1] == '2' &&
url[i+2] == '0') {
newStr[pos++] = ' ';
i += 2;
} else
newStr[pos++] = url[i];
}
strcpy(blah, newStr);
}
__________________
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
Thanks a lot tempest!!! Definetly gets me going in the right direction
![]() I've been struggling with this for a while now, and other forums didnt seem to help. Thanks again! :rock: |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Dec 2004
Posts: 8
Rep Power: 0
![]() |
On second thought/compile, it works flawlessly,
Thanks again! ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|