Sunday, November 22, 2009

Convert string to all caps in C

/*Sample code to convert to ALL CAPS a given string. */

#include
<stdio.h>
#include<string.h>

main()
{

int len =0;
int i =0;

char *str="quick BroWn Fox juMP ovEr the HeAd";
char *up_str;

len=strlen(str);
/*strlen does not include '\0' in the count so we allocate space for it*/
up_str=malloc((len+1)*sizeof(char));

printf("\nThis is the sample string: %s\n", str);
printf("\nThe length: %d",len);

for(i=0;i<=len;i++){ *(up_str+i)= toupper(*(str+i));
/* In C, *(array+1) == array[1] */
if(i==len){
*(up_str+i)='\0';
}
}

printf("\nThe upper string: %s\n", up_str);
free(up_str);
system("PAUSE");
}

Search between two tables

With an account POID, search for the product name of its products.

The sql template to use here would be:

"select X from /product 1, /purchased_product 2 where ( 2.F1 = V1 and 1.F2 = 2.F3 ) "

where F1 = PIN_FLD_ACCOUNT_OBJ
F2 = PIN_FLD_POID
F3 = PIN_FLD_PRODUCT_OBJ
V1 = account POID

The search flist looks like this:

0 PIN_FLD_POID POID [0] 0.0.0.1 /search 0 0
0 PIN_FLD_TEMPLATE STR [0] "select X from /product 1, /purchased_product 2 where ( 2.F1 = V1 and 1.F2 = 2.F3 ) "
0 PIN_FLD_FLAGS INT [0] 256
0 PIN_FLD_ARGS ARRAY [1] allocated 20, used 1
1 PIN_FLD_ACCOUNT_OBJ POID [0] 0.0.0.1 /account 20454
0 PIN_FLD_ARGS ARRAY [2] allocated 20, used 1
1 PIN_FLD_POID POID [0] NULL poid pointer
0 PIN_FLD_ARGS ARRAY [3] allocated 20, used 1
1 PIN_FLD_PRODUCT_OBJ POID [0] NULL poid pointer
0 PIN_FLD_RESULTS ARRAY [0] allocated 20, used 1
1 PIN_FLD_NAME STR [0] ""