c program(multi-character character constant)

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
Rich (BB code):
  #include<stdio.h>
#include<ctype.h>
void work(void);
  double fah_2_cels(double fahr );
  double cels_2_fahr(double cels);
  int main(void)
  {
    char more;
    puts("\n enter the temperature followed by f for fahr and c for cels");
    do{
      work();
      puts("\n do you want to continue(Y/N)?");
      scanf("%c" ,&more);
      more =toupper(more);
    }while(more!='N');
    return 0;
  }
  void work(void)
  {
    double temp;
    //char ch[6];
    double num,fahr,cels;
    printf("enter the temperature");
    scanf("%lg %c",&num,&num);
    if (num='70')
    {
      temp=fah_2_cels(num);
      printf("temperature in cel is %g",temp);
 }
    else
      temp=cels_2_fahr(num);
      printf("temperature in fahr is %g",temp);
  }//closes void work()
  double fah_2_cels(double fahr)
  {
  return ((5.0/9.0)*(fahr-32.0));
  }
  double cels_2_fahr(double cels)
  {
    return ((9.0/5.0)*cels +32.0); //If you find that the results are off look at these functions
  }
this program is working ok but it give me warninig (multi character character constant in line 12 ) how can i fix this
thanks
 
Last edited:

WBahn

Joined Mar 31, 2012
30,055
This is probably the line

*ptr <='127' ||*ptr >= '0')

I am guessing you want

*ptr <=127 ||*ptr >= 0)
I don't see this in the code at all.

But I do see this:

Rich (BB code):
    double num;
    ...
    scanf("%lg %c",&num,&num);
    if (num='70')
You have told scanf that you will supply the addresses of a double and a char. Yet you supply the addresses of two doubles. Bad karma.

On top of that, you supply the same address for both. This invokes unspecified behavior (I'm pretty sure). Do YOU know which value ends up in num? Why that one and not the other one?

Then, you are comparing num (a variable of type double) to the constant value '70'. But what the heck is the value '70'? '7' would be the ASCII code (assuming your implementation used ASCII) for the character that looks like a 7. But there is no ASCII code for the character that looks like a 70 because there is no such character. You have a character constant that has more than one character. The compiler is probably using the first character and throwing a warning.
 

spinnaker

Joined Oct 29, 2009
7,830
I don't see this in the code at all.

But I do see this:



You have told scanf that you will supply the addresses of a double and a char. Yet you supply the addresses of two doubles. Bad karma.

On top of that, you supply the same address for both. This invokes unspecified behavior (I'm pretty sure). Do YOU know which value ends up in num? Why that one and not the other one?

Then, you are comparing num (a variable of type double) to the constant value '70'. But what the heck is the value '70'? '7' would be the ASCII code (assuming your implementation used ASCII) for the character that looks like a 7. But there is no ASCII code for the character that looks like a 70 because there is no such character. You have a character constant that has more than one character. The compiler is probably using the first character and throwing a warning.
OP has already solved the issue and has updated the OP for some reason. Why respond with an answer when the OP has solved the issue?
 

WBahn

Joined Mar 31, 2012
30,055
OP has already solved the issue and has updated the OP for some reason. Why respond with an answer when the OP has solved the issue?
I don't see where the issue I was talking about has been solved at all. If that code is now "running perfectly" it is only by pure luck because of the issues I raised that I don't see mentioned anywhere else in this thread.

Now, after posting my response pointing out things that are NOT pointed out in this thread, someone points out that the OP has posted this same code in some other thread and that the issues I raised are discussed in that thread.

How the hell am I supposed to know that?!

I guess since there's always the chance that any issue has already been solved in some other thread, I should just not bother providing any answers at all.

Fine. Goodbye.
 

spinnaker

Joined Oct 29, 2009
7,830
I don't see where the issue I was talking about has been solved at all. If that code is now "running perfectly" it is only by pure luck because of the issues I raised that I don't see mentioned anywhere else in this thread.

Now, after posting my response pointing out things that are NOT pointed out in this thread, someone points out that the OP has posted this same code in some other thread and that the issues I raised are discussed in that thread.

How the hell am I supposed to know that?!

I guess since there's always the chance that any issue has already been solved in some other thread, I should just not bother providing any answers at all.

Fine. Goodbye.

Yeah sorry really the OPs fault. Ge did mention in the post above that the issue is solved.

I wonder sometime, after reading some of these post like the OP's , if they have ever used a forum before. Rules are pretty much the same anywhere not to mention common sense.
 

spinnaker

Joined Oct 29, 2009
7,830
need a ranking or reputation system so each post (question or reply) can be graded.
Agreed. While stackoverflow bites the bit one as far as usability is concerned they do have sort of a ranking.

The other nice feature they have is to mark a post as the answer.


Instead of number of posts to post in certain forums, you should have to have a certain ranking to earn the privilege.

Oh and you should get points knocked off bug tie for not using punctuation or capitalizing sentences. :)
 
Top