Advertisement
ledrose

ProjectColorNumbers

Dec 1st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <math.h>
  6.  
  7. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  8. char text[]="color=blue&icon=search.png&number=95684&submit=plus";
  9. char output[300];
  10. int main(int argc, char *argv[]) {
  11.     char *pch =strtok(text,"&=");
  12.     char imgbegin[] = "<img height='200px' width='200px' alt='img' src='img/";
  13.     char imgend[]=".png'>\n";
  14.     char imgnum[12],imgnumr[12];
  15.     int num,n,x,k=0,randn,imgval=5;
  16.     while (pch!=NULL) {
  17.         if (strcmp(pch,"number")==0) {
  18.             pch = strtok(NULL,"&=");
  19.             break;
  20.         }
  21.         pch = strtok(NULL,"&=");
  22.     }
  23.     num=atoi(pch);
  24.     x=num;
  25.     while (x!=0) {
  26.         x=x/10;
  27.         k++;
  28.     }
  29. //  printf("%d\n",k);
  30.     srand(time(NULL));
  31.     while (k!=0) {
  32.         n=(num%(int)pow(10,k))/(int)pow(10,k-1);
  33.         randn=rand()%imgval;
  34.         sprintf(imgnum,"%d",n);
  35.         sprintf(imgnumr,"%d",randn);
  36.         strcat(output,imgbegin);
  37.         strcat(output,imgnum);
  38.         strcat(output,imgnumr);
  39.         strcat(output,imgend);
  40.         k--;
  41.     }
  42.     printf("%s\n",output);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement