debugging perceptron for digital AND circuit
You have several flaws in your code that will lead to unexpected behavior. I identified the following flaws you need to address. Once you have fixed them, you should output your updated weights during each step of training to see what the learning algorithm actually does and if it is going in the right direction. I will not address pure style aspects (like using a simpler case-statement instead of a series of ifs and stuff like that) and focus on the real errors.

Skipping training case 1

Once you are in training case 4, you set j to 1, expecting to use training case 1 next. But later in your code you increase j by one (j++) and go directly to training case 2, skipping the first one. This means you only run through training case 1 during your first pass of the loop.

Assigning j a value instead of comparing it


  if(j=1)


The if statement will always be true, because you do not compare j to 1 but you set j to 1. You basically assign a value and test if the value is true. Correct would be:


  if(j==1)


Ignoring bias during test

During the test steps after training you forget to add the bias that you used during training:


  output = weight1*input1 + weight2*input2


should actually be:


  output = weight1*input1 + weight2*input2 + 2


Otherwise your perceptron behaves differently during training and testing.

Perceptron output must be 1 or 0

Those were all implementation issues. This point actually seems to come from a misunderstanding of perceptrons. A real perceptron can either fire or not, meaning it outputs either 1 or 0, nothing in between. You calculate your output the following way and use the output to compare to the expected output:


  output = weight1*training1 + weight2*training2 + 2;
  
  if(output != expectedoutput )


Your output here is a float value. Only in edge cases it will result in 1 or 0. What you actually want to do for a real perceptron is:


  if (weight1*training1 + weight2*training2 + 2 >= 0) {
   output = 1
  } else {
   output = 0
  }
  
  if(output != expectedoutput)


After you fixed those errors and studied the output of your learning algorithms, you should be able to get the perceptron to work. If you have any questions, please leave a comment and I will try to help.



Edit:

I don't have a C compiler here, so I quickly implemented your solution with my suggested fixes in Python 3.6 and the results are very close to the correct solution. The final weights obviously have to be -1 and -1 for an AND Gate with bias 2. The learning process gets very close but never reaches -1 and -1 exactly, which leads to the wrong output in the end. This is a very good showcase to illustrate why you prefer a sigmoid neuron instead of a perceptron in modern neural networks. Here is a relevant question from cross-validated concerning the difference of those two types of neurons.