Crappiest ... code listing ... ever!
printf(“Enter the total no. of elements \n”);
printf(“%d \n”,temp); //to check
printf(“Enter the N elements one by one, with element# %d: \t”,dial+1);
Now look at these lines:
What are you trying to do? arr is a single C-style string. Since you have not initialized it, it contains garbage
, which is to say whatever effectively random values just happened to have been left there. Never attempt to use uninitialized variables!
Also arr[dial] would be a character, a single character
. So then why are you trying to compare it with the address
of a string literal? What do you think that you are trying to accompish?
If you are going to compare a single character to anything, then it needs to a another single character!
What did the compiler's warnings tell you? Don't tell me there weren't any warnings! The compiler had to squack and complain very loudly at the nonsense that you were feeding it! Don't tell me you were stupid enough to turn the warnings off. Or even more stupid enough to have ignored the warnings. Never ever ignore warnings!
And never run a program that hasn't compiled cleanly -- meaning without any warnings. Because when a compiler issues warnings, it's because it's confused by the grave mistakes you made and, in its confusion, will guess at what you intended, which will almost never be what you did intend, and so generate code that will not do what you wanted it to do! Never ignore warnings!
They are much more important than error messages!
Even if you had attempted something like
if (arr != "NULL")
with the intention of testing whether arr contained a string that was different than "NULL", that would not do what you thought it did. All you would be doing would be to compare memory addresses, testing whether the literal "NULL" was located in the same place in memory as the arr array, which they are not. That means that you would never ever be able to leave that while loop, which is an infinite loop problem, not your stated "it ignored the while". Though since you are testing a character against the address of a string, who knows what the crazy code generated by your poor compiler could actually be doing?
Your code is terminally messed up. Turn warnings on, read the warnings, and make the corrections needed.
And the final statement in your main function needs to return an int. Try return 0;
, which indicates that the program had run successfully and did not encounter any run-time errors.