fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. // input-string, input-string-size
  6. i=-1,j,s=1,x;C(char*n){while(n[++i])s+=isdigit(n[i])?n[i]*2+1:2;char*m=(char*)malloc(s);for(i=j=-1;n[++i]&(m[++j]='|');)if(n[i]=='/')m[++j]='\n';else if(isdigit(n[i]))for(x=n[i]-'0';x;--x&&(m[++j]='|'))m[++j]=' ';else m[++j]=n[i];m[++j]='\0';return m;}
  7.  
  8. // input-string, input-string-size
  9. char* C2(char*n)
  10. {
  11. int i=-1,j,s=1,x;
  12. while(n[++i])s+=isdigit(n[i])?n[i]*2+1:2;
  13. char*m=(char*)malloc(s);
  14.  
  15. i=j=-1;
  16. while(n[++i])
  17. {
  18. m[++j]='|';
  19.  
  20. if (n[i]=='/')
  21. m[++j]='\n';
  22. else if (isdigit(n[i]))
  23. for(x=n[i]-'0';x;--x&&(m[++j]='|')) m[++j]=' ';
  24. else
  25. m[++j]=n[i];
  26. }
  27.  
  28. m[++j]='|';
  29. m[++j]='\0';
  30. return m;
  31. }
  32.  
  33. int main(void)
  34. {
  35. // tests
  36. printf("\n---------------------------\n");
  37. printf(C("8/8/8/8/8/8/8/8"));
  38. printf("\n---------------------------\n");
  39. printf(C("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"));
  40. printf("\n---------------------------\n");
  41. printf(C("r1bk3r/p2pBpNp/n4n2/1p1NP2P/6P1/3P4/P1P1K3/q5b1"));
  42. printf("\n---------------------------\n");
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
---------------------------
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
---------------------------
|r|n|b|q|k|b|n|r|
|p|p|p|p|p|p|p|p|
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
|P|P|P|P|P|P|P|P|
|R|N|B|Q|K|B|N|R|
---------------------------
|r| |b|k| | | |r|
|p| | |p|B|p|N|p|
|n| | | | |n| | |
| |p| |N|P| | |P|
| | | | | | |P| |
| | | |P| | | | |
|P| |P| |K| | | |
|q| | | | | |b| |
---------------------------