net11

Unpredictable output while working with numeric user input in C

Discussion created by net11 on Dec 2, 2009
Latest reply on May 16, 2010 by net11

Hi,

 

I am new to the CodeWarrior IDE and trying to get familiar with the IDE by writing simple C programs.

The board I am using is MCF5234BCCKIT eval board and the version of CodeWarrior is the special freely downloadable version 7.1

 

I tried writing very simple code with scanf() and fgets() type of functions to get user input and do some arithmetic operations on them. The target is console internal RAM. The output of the program is usually large numbers which could possibly be garbage values or addresses. for example, if a value of 20 in entered in a scanf() and assigned to a varibale, and I try printing the variable value to the console with a printf() is shows up as something like 536935188. Also, within the code if the value id incremented by say, 1, I see the output as 1 added to this large value.

 

What am I doing wrong?  

Outcomes