Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void print(int s, int v1, int v2) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
- {
- int main_buf[2048];
- int buffer_pos; int string_pos; int q;
- for ( ; s[string_pos] != '%'; ++string_pos )
- {
- main_buf[buffer_pos] = s[string_pos];
- ++buffer_pos;
- }
- int values[]={v1,v2};
- int val_index = 0;
- do
- {
- TraceS("Val index is: "); Trace(values[val_index]); TraceNL();
- switch(s[string_pos+1])
- {
- case 'S':
- case 's':
- {
- int ptr = values[val_index];
- //for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
- for ( q = 0; ptr[q]; ++q ) //until we reach NULL
- {
- main_buf[buffer_pos] = values[val_index[q]]; //copy the string passed as a param
- //over to the buffer
- ++buffer_pos;
- }
- ++string_pos;
- ++string_pos;
- break;
- }
- case 'F':
- case 'f':
- {
- int i_val[12];
- ftoa(i_val,values[val_index]);
- for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
- {
- main_buf[buffer_pos] = i_val[q];
- ++buffer_pos;
- }
- ++string_pos;
- ++string_pos;
- break;
- }
- case 'D':
- case 'd':
- {
- int f_val[12];
- itoa(f_val,values[val_index]);
- for ( q = 0; (f_val[q]); ++q )
- {
- main_buf[buffer_pos] = f_val[q];
- ++buffer_pos;
- }
- TraceS(f_val);
- ++string_pos;
- ++string_pos;
- break;
- }
- default: ++buffer_pos; break;
- }
- //we copied the insertion, so, resume the rest o the string:
- for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
- {
- //copy the rest of the string:
- main_buf[buffer_pos] = s[string_pos];
- ++buffer_pos;
- }
- //for some reason, placing this here, val_index == 5 ?!
- ++val_index; //increase for overloads
- }while(false);
- //while((s[string_pos])); //until we reach null in the main buffer
- TraceS(main_buf); //TraceNL();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement