473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to put char by char from one string to enother?

Hi.

Got such a problem. I wrote a url decoding programm. The main idea is, that programm take char by char from incoming string, decides what changes must be made, and then inserts them to enother. But, seems, like there is a logical error, because it runs endless circles and never comes to an end. Could someone fix an error?
Expand|Select|Wrap|Line Numbers
  1. string Utils::urldecode(string incoming)
  2. {
  3. string outgoing;//RESULT STRING
  4. char current;//CURRENT CHAR
  5. char buffer[2];//BUFFER TO DECODE URL
  6. int read = 0;//READ POSITION
  7. int write = 0;//WRITE POSITION
  8.  
  9. int value[2];
  10. int value_pointer = 0;
  11. int symbol;//NUMERIC VALUE OF CHAR
  12. char result;
  13. while(current!=EOF)
  14. {
  15. current = incoming[read];
  16. switch(current)
  17. {
  18. case '+':
  19. outgoing[write] = ' ';
  20. read++;
  21. write++;
  22. break;
  23. case '%':
  24. read++;
  25. current = incoming[read];
  26. while(value_pointer<2)
  27. {
  28. current = incoming[read];
  29.   switch(current)
  30.       {
  31.         case 'A':
  32.         value[value_pointer]= 10;
  33.         read++;
  34.         value_pointer++;
  35.         break;
  36.         case 'B':
  37.         value[value_pointer]= 11;
  38.         read++;
  39.         value_pointer++;
  40.         break;
  41.         case 'C':
  42.         value[value_pointer]= 12;
  43.         read++;
  44.         value_pointer++;
  45.         break;
  46.         case 'D':
  47.         value[value_pointer]= 13;
  48.         read++;
  49.         value_pointer++;
  50.         break;
  51.         case 'E':
  52.         value[value_pointer]= 14;
  53.         read++;
  54.         value_pointer++;
  55.         break;
  56.         case 'F':
  57.         value[value_pointer]= 15;
  58.         break;
  59.         default:
  60.         value[value_pointer]= atoi(&current);
  61.         read++;
  62.         value_pointer++;
  63.         break;
  64. }
  65. }
  66. symbol = value[0]*16 + value[1];
  67. result = symbol;
  68. outgoing[write]=result;
  69. value_pointer = 0;
  70. read++;
  71. write++;
  72. break;
  73. default:
  74. outgoing[write]=current;
  75. read++;
  76. write++;
  77. break;
  78.  
  79. }
  80. }
  81. return outgoing;
  82. }
PS. By the way, if you find an error, you may use this function for decoding HTML form requests
May 17 '07 #1
2 2161
please remove this topic, there is no more need in answer, i solved the problem
May 17 '07 #2
Ganon11
3,652 Expert 2GB
No need to delete it, unless you want to remove the code from the public. Glad to see you found your solution, though :D
May 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Yang Song | last post by:
HI, I am a little confused about char * and char. How would I be able to return a char* created in a function? Is new() the only way? How would I be able to return a point and a value at the same...
24
by: Norm | last post by:
Could someone explain for me what is happening here? char *string; string = new char; string = "This is the string"; cout << string << std::endl; The output contains (This the string) even...
9
by: Christopher Benson-Manica | last post by:
I need a smart char * class, that acts like a char * in all cases, but lets you do some std::string-type stuff with it. (Please don't say to use std::string - it's not an option...). This is my...
22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
8
by: andrew.fabbro | last post by:
In a different newsgroup, I was told that a function I'd written that looked like this: void myfunc (char * somestring_ptr) should instead be void myfunc (const char * somestring_ptr) ...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.