Saturday 15 January 2011

Garbage values assigned while using dynamic input; in C language -


The problem is that the attributes in the output are assigned SP, BP, floating, cold, fever and abdomen with garbage values. Moreover, the string that is inserted for symp [i] is not properly stored. This is not a complete program, but still some additional work can be done in it.

There are programs like this .. The header files are stdio.h and conio.h

  #include in the & lt; stdio.h & gt; #to & lt include, conio.h & gt; Zero main () {four * symp [10]; Int n = 0, I, SP, DP, cold, fever, stomach; Float floating; Clrscr (); Printf ("Enter the temperature of your body:"); Scanf ("% f", & amp; temp); Printf ("Enter your systolic BP:"); Scanf ("% d", & amp; nbsp;); Printf ("Enter your Diastolic BP:"); Scanf ("% d", & amp; DP); Printf ("Enter the number of symptoms:"); Scanf ("% d", & amp; n); Printf ("Enter the symptoms you have, one after the other \ n"); Fever = cold = stomach = 0; (I = 0; i & lt; n; i ++) for {scanf ("% s", symp [i]); Printf ("I =% d \ trillion =% d \ n", I, n); If (symp [i] == "cough") (cold = cool + 1;) if (symp [i] == "sneezing") {cold = cool; 1;} if (symp [i] == "walk (Cold = cool; + 1;} (symp [i] == "headache") {cold = cold; 1; fever = fever + 1;} if (symp [i] == "cold") {fever = Fever = 1;} if (symp [ii] == "weakness") {fever = fever + 1;} if (symp [i] == "petpain") (abdomen = stomach + 1; if (symp [i] == "vomiting") (abdomen = abdomen = 1; fever = fever + 1;} if (symp [i] == "throat_pain") {cold = cool; 1;} if (symp [i] == "body_pain Printf ("Your temperature is:% f \ n", floating); Printf ("Your BP is:% d /% d \ n", sp, Dp; printf ("symptoms": \ n "); for (i = 0; i & lt; n; i ++) {printf ("% s \ n ", symp [i]);} Printf ( "Cold:% d \ nfever:% d \ nstomach:% d", cold, fever, stomach); getch ();}  

You can not compare with char [] with a constant string with == , you strcmp Or strncmp , something like this:

  if (strmp (symp [i], "headache"))  

You address to scanf ("% s", ...) , something like this:

  scanf ("% s ", And symp [i]);  

No comments:

Post a Comment