Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 13th, 2004, 8:27 AM   #1
Scrag
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 Scrag is on a distinguished road
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
Scrag is offline   Reply With Quote
Old Dec 13th, 2004, 2:49 PM   #2
plox
Newbie
 
Join Date: Dec 2004
Posts: 6
Rep Power: 0 plox is on a distinguished road
Send a message via AIM to plox
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>
plox is offline   Reply With Quote
Old Dec 13th, 2004, 3:05 PM   #3
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4 Benoit is on a distinguished road
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
Benoit is offline   Reply With Quote
Old Dec 13th, 2004, 3:32 PM   #4
Scrag
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 Scrag is on a distinguished road
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!!
Scrag is offline   Reply With Quote
Old Dec 13th, 2004, 3:41 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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..
__________________

tempest is offline   Reply With Quote
Old Dec 13th, 2004, 6:59 PM   #6
amado
Newbie
 
Join Date: Dec 2004
Posts: 3
Rep Power: 0 amado is on a distinguished road
Don't know what platform u're writing the program in but there is a function in msdn that does this for you ::: InternetCanonicalizeUrl
amado is offline   Reply With Quote
Old Dec 13th, 2004, 9:05 PM   #7
Scrag
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 Scrag is on a distinguished road
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
Scrag is offline   Reply With Quote
Old Dec 13th, 2004, 9:33 PM   #8
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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);
}
__________________

tempest is offline   Reply With Quote
Old Dec 13th, 2004, 10:50 PM   #9
Scrag
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 Scrag is on a distinguished road
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:
Scrag is offline   Reply With Quote
Old Dec 13th, 2004, 11:27 PM   #10
Scrag
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 Scrag is on a distinguished road
On second thought/compile, it works flawlessly,

Thanks again!

Scrag is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC