Note that there are some explanatory texts on larger screens.

plurals
  1. POc pass a string to function then return a string
    text
    copied!<p>After exploring the internet, i've wrote the following script, but still got errors, anyone knows what the errors are?( the line with //err)</p> <pre><code>typedef struct name_value_set { char name[250]; char value[250]; } nv_set; char * getInput2(char *param) { char *my_data=0; int data_len; char *tmp_ptr, *tmp; int i; nv_set *nv; data_len=atoi(getenv("CONTENT_LENGTH")); char field[data_len]; my_data=(char*)malloc(sizeof(char)*(data_len+1)); fread(my_data,1,data_len,stdin); i=0; while (my_data[0]!='\0') { tmp=split(my_data,'='); // err makespace(tmp); tmp=convert(tmp); // err strcpy(nv[i].name,tmp); // tmp=split(my_data,'&amp;'); //err makespace(tmp); // tmp=convert(tmp); // err strcpy(nv[i].value,tmp); // i++; } i--; // int j=0; for (j=0; j&lt;i; j++) { if(nv[j].name == param) { return nv[j].value; } } void makespace(char *s) { int i,len; len=strlen(s); for (i=0;i&lt;len;i++) { if (s[i]=='+') s[i]=' '; } } char *split(char *s, char stop) { char *data; char *tmp; int i,len,j; len=strlen(s); tmp=s; data=(char*)malloc(sizeof(char)*(len+1)); for (i=0;i&lt;len;i++) { if (s[i]!=stop) data[i]=s[i]; // else { i+=1; // break; } } data[i]='\0'; for (j=i;j&lt;len;j++) s[j-i]=tmp[j]; s[len-i]='\0'; return data; } char *convert(char *s) { int x,y,len; char *data; len=strlen(s); data=(char*)malloc(sizeof(char)*(len+1)); y=0; for (x=0;x&lt;len;x++) { if (s[x]!='%') { data[y]=s[x]; // y++; } else { data[y]=(char)(16*hexa(s[x+1])+hexa(s[x+2])); y++; x=x+2; } } data[y]='\0'; return data; } int hexa(char c) { switch(c) { case '0':return 0; case '1':return 1; case '2':return 2; case '3':return 3; case '4':return 4; case '5':return 5; case '6':return 6; case '7':return 7; case '8':return 8; case '9':return 9; case 'A':return 10; case 'B':return 11; case 'C':return 12; case 'D':return 13; case 'E':return 14; case 'F':return 15; } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload