Question

I kept getting Illegal use of character on the line that checks if a variable is empty or null.

Does anyone know why this happened?

the error points here:

if((fa == "" && fp == "") || (fb == "" && fp == "")){

though it worked before i just dont know whats causing this error.

Edit:

changed the code now the errors are too few parameters for function sinfa.

i only want to pass one parameter at a time to this function, is it possible or do i have to create another function to do that so that i can cater to them individually?

thank you. :)

#include<stdio.h>

#include<conio.h>
#include<math.h>
#define PI 3.14159265359

float sinfa(float num1,float num2)
{
    float fc;
    float powers;
    float rad_angle;

    if(num1 != 0){
    rad_angle = num1 * (PI / 180.0);
    powers = pow(rad_angle,4);
    fc = sin(rad_angle)-powers+1;
    }else{
    rad_angle = num2 * (PI / 180.0);
    powers = pow(rad_angle,4);
    fc = sin(rad_angle)-powers+1;
    }
    return (fc);
}

float sinp(float p1)
{
    float fop;
    float ppowers;
    printf("%f",p1);
    ppowers = pow(p1,4);
    fop = sin(p1)-ppowers+1;
    return (fop);
}

float tp(float fa,float fb,int num1,int num2)
{
    float p;
    float fm2 = fa*num2;
    float fm1 = fb*num1;
    p = fm2-fm1/fa-fb;
    return (p);
}

float main()
{
    float num1;
    float num2;
    float fa;
    float fb;
    float p1;
    float fp;

    clrscr();
    printf("Enter number 1: \n");
    scanf("%f", &num1);
    getch();
    printf("Enter number 2: \n");
    scanf("%f", &num2);
    getch();
    clrscr();

    if((fa == 0 && fp == 0) || (fb == 0 && fp == 0)){
        fa = sinfa(num1);
        fb = sinfa(num2);
        p1 = tp(fa,fb,num1,num2);
        fp = sinp(p1);
    }else{
        if((fa*fp) < 0){
            num1 = num1;
            num2 = p1;
            fa = sinfa(num1);
            fb = sinfa(num2);
            p1 = tp(fa,fb,num1,num2);
            fp = sinp(p1);
        }
        if((fb*fp)< 0){
            printf("\n 2");
            getch();
        }
    }
}
Was it helpful?

Solution 3

Error appears because you're comparing float with string literal, ie:

if((fa == "")

You can only do a comparison of float with a numeric/float literal, ie:

if((fa == 0.0

Recall that there's no such concept as NULL / uninitialized for primitive type such as float. Instead they typically default to 0.

Hence having the following means f value will be literal 0

float f;

OTHER TIPS

"" is not a number. You cannot compare a number to it.

The error appears because you try to compare a literal string to a float value.

Your test for empty strings is also wrong. To check if a string is null or empty you should use the following code (assuming that type of fp is char *):

if(fp == NULL || *fp == '\0')

The sinfa function doesn't have a valid prototype. Add type specifiers to the parameters num1, num2 in the function definition.

And according to the Standard the prototype of the main function should be either

int main(void)

or

int main(int argc, char *argv[])

Yours is wrong.

I suppose you're trying to check if there were errors during scanf input conversion. In order to do that you should inspect the result of scanf and check the gloval error state using the ferror function (or check the errno value directly).

float fa;
float fb;
float p1;
float fp;

clrscr();
printf("Enter number 1: \n");
scanf("%f", &num1);
getch();
printf("Enter number 2: \n");
scanf("%f", &num2);
getch();
clrscr();


if((fa == 0 && fp == 0) || (fb == 0 && fp == 0)){

Where are you assigning a value to fa, fb or fp? Nowhere. This is undefined behaviour.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top