Limitation of C Language?

Hello readers,
Hex 11 is back with one more of his experiences. This experience is about what happens when non-coders guys sit to write a code in C & that creates magic. Many of you might agree with me that there are notable limitations of C. Recently, I was writing my code for Simplified DES in Turbo C, with my friend Bhavesh (Hex 99).
Let me first brief you about DES.
Problem Definition:
DES stands for Data Encryption Standards, used to provide & improve the security & authenticity of data. First the sender needs to develop 10-bit key & then permutation is applied to the initial key. Then the permuted key is broken into two parts each of 5-bit. Then left shift operation is applied on both the parts & then permuted with given 8-bit permutation key that gives key K1. This process is repeated again to generate key K2.
CODE:
#include<stdio.h>
#include<conio.h>bha
void main()
{
int i,j;
int key[10],key2[10],p[10],ls1[5],ls2[5]; //Refer to solution mentioned below
clrscr();
printf("Enter 10-bit key:");
for(i=0;i<10;i++)
{
scanf("%d",&key[i]); //10-bit key
}
for(i=0;i<10;i++)
{
printf("%d",key[i]);
}
printf("\nEnter permuation key:");
for(i=0;i<10;i++)
{
scanf("%d",&p[i]); //Enter permutation order
key2[i]=key[p[i]]; //10-bit key permutated
}
printf("\n");
printf("New Key:");
for(i=0;i<10;i++)
printf("%d",key2[i]);
printf("\n");
for(i=0;i<5;i++)
{
ls1[i]=key2[i];//Part 1 of 10-bit key
}
//Value printed in part 1 array
printf("\nPart 1:");
for(i=0;i<5;i++)
{
printf("%d",ls1[i]); //Print part 1
}
//Value printed in array part 1
for(i=5;i<10;i++)
{
ls2[i]=key2[i];//Part 2 of 10-bit key
}
printf("\nPart 1:");
for(i=0;i<5;i++)
{
printf("%d",ls1[i]); //Print part 1
}
// As the variable is same then also printf below part 2 changes value in part 1 array
printf("\nPart 2:");
for(i=5;i<10;i++)
{
printf("%d",ls2[i]); //Print part 2
}
//Rest of the code not written to as the problem persists here
getch();
}
Output:

While executing the code I get different values for the array(ls1) part 1 at two different printf statements, as you can see in the above image. Can anyone tell me why C compiler is treating the code in such a manner as I am printing same array at two different places & it is giving me different output & that too I havn't overwritten the array.
I hope you have understood the problem the code shows during output.
I am not much fond of coding & when I do coding these sorts of errors are found lol…& guys you only tell me how will one be interested if compiler only gives errors. I think there are many limitations of C compilers & let me tell you that I am using Turbo-C compiler, that is widely used at present. This is the first time in my life that I have used comments in a C program. I have work hard to code it & to my enthusiasm I am challenging C & showing its limitations.
Can anyone tell me the reason why is this happening in this code?
So let's now come to the climax part. One day before posting this article, I was talking with Ronak Baldha (Hex 22) about the problem & trying to find the error. But actually there wasn't any error as code was executing. So where is the problem as it shows different outputs for same array? Then, Ronak (too not fond of coding) took out a rabbit from his hat & we had the solution.
Solution:
As you can see that I have highlighted the two arrays used by me- ls1 & ls2. Now, actually there was no error in the code but the problem was that I was trying to print the values at index 5-9 which never existed in any of the array. So it was showing me wrong output. Actually, like JAVA, C is not able to generate exceptions for array where it should generate "ArrayOutOfBoundException". So, after lots of thinking we were on some solution for this problem.
The limitation of C is clearly seen as C compilers can only identify errors & can't handle exceptions. This is the reason why applications coded in C fail often in real time scenario. The world has now shifted to OO languages because of these limitations of procedural languages. It's time to move on with the real stuff applications use C only for conceptual basis rather than programming.
Moral of the Story:
Only people who are not fond of coding can generate these types of outputs &, one more step ahead, same type of people only can find these limitations too!
Thank you guys for spending time to read my experience & I hope it helps you too to explore more tech stuff with me…Good bye…enjoy!!





