Click here to Skip to main content
14,328,128 members
Rate this:
Please Sign up or sign in to vote.
See more:
Could someone explain this code:

#include <stdio.h>
#define MAX 10
int main()
{
char array[MAX][MAX], c = 0;
int d = 1, x = 0, i, j;
do scanf("%s", array[x]);
while (array[x++][0] != '0');
{
float* pf;
int xx, *pi = (int*)&array[0][7];
xx = ((*pi) & 0x41000000);
pf = (float*)&xx;
printf("%5.2f\n", *pf);
}
for (c-=--x; c++&**array; d+=!(c<<x>0)) d<<=1;
d -= c;
for (i = 0; i < x;
i==1?printf("%c ", array[i][x>>1]):i, ++i)
for (j = 0; j <= x - i;
printf("%c", array[i][j++]));
printf("%x", d);
return 0;
}


Example input: code project
Output: 2.00
codprr 6

I debugged it with Code Blocks, but didn't understand how it works. What tools for debugging would you suggest?
Posted
Comments
PIEBALDconsult 1-Mar-15 12:19pm
   
Better formatting might help.
   
What for?.. :-)
Please see the comments below.
—SA
Richard MacCutchan 1-Mar-15 12:20pm
   
Impossible to understand. It looks like some 'clever' code that produces some special results.
   
The question is: does it worth understanding or even reading? I doubt it... :-)
—SA
Albert Holguin 1-Mar-15 14:41pm
   
That's horrible code... you should throw that away and forget you ever saw it.
   
Best advice so far.
—SA
   
You need to understand: "explaining code" is a waste time and not anything constructive or useful. Write your own code, so you could at least explain the purpose of each piece and ask questions if you have problem with it.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I would suggest using gdb debugger to run and trace each variable. Use it to stop at different points.
Else format it nicely with brackets and run in Visual Studio with breakpoints. Watch each variable in each loop.
   
Comments
   
I wonder why bothering... :-)
—SA
Member 11489314 2-Mar-15 3:05am
   
I had exam assignment, and this type of problem showed up. The code is given and you have to analyze it line by line. If anyone has time to explain this code in shorts I would be very thankful.
   
I'm not sure your school really teaches students...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100