Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: help plz………….. #3640
    LenoraRamsey
    Participant

    Actually, In C float and double has only two differences. one is size. and another one is storage in memory.
    float has only single precision. But double has double precision.

    So, In your code you are trying to differentiate this. But it gives output as hello because it is equal.
    double 0 is equal to float 0.

    If you want differentiate float and double try this code.


    #include
    main()
    {
    long double a =0.0;
    if(a>=(float)0.0)
    printf("hi");
    else
    printf("hello");
    }

    It will prints hi.


    #include
    main()
    {
    long double a =0.1;
    if(a>=(float)0.1)
    printf("hi");
    else
    printf("hello");
    }

    It will prints hello.

    I think now you can get the difference.

    in reply to: need help in adding a charecter to the file name #3610
    LenoraRamsey
    Participant

    Try this code for you requirement It will solve you problem.
    As you want it will check for abcd if it is there it will check for abcd1 file.


    #include
    #include
    #include
    #include

    char *reverse(char s[])
    {
    int c,i,j;

    for(i=0,j=strlen(s)-1;i {
    c=s;
    s
    =s[j];
    s[j]=c;
    }
    return s;
    }



    char *itoa(int n)
    {
    char s[100];
    int i,sign,ind=0,mod,w=0;
    if((sign=n)<0){
    if(sign<=INT_MIN)
    {
    mod=-(n%10);
    n=n/10;
    ind=1;
    }
    n=-n;
    }
    i=0;
    do
    {
    if(ind==1)
    {
    s[0]=mod+'0';
    i++;
    ind=0;
    }
    s[i++]=n%10+'0';

    }while((n/=10)>0);
    s
    ='';
    return (reverse(s));
    }

    int exists(const char *filename)
    {
    FILE *f = fopen(filename, "r");
    if (!f) return 0;
    fclose(f);
    return 1;
    }

    int main ( )
    {
    char str [1024];
    strcpy(str,"abcd");
    int num = 0;
    int created = 0;
    while(created == 0)
    {
    num++;
    if(exists(str))
    {
    char numb[100];
    strcpy(str,"abcd");
    strcpy(numb,"");
    strcpy(numb,itoa(num));
    strcat(str,numb);
    }
    else
    {
    FILE *f=fopen(str,"w");
    printf("%s file createdn",str);
    created=1;
    fclose(f);
    }
    }
    return 0 ;
    }
Viewing 2 posts - 1 through 2 (of 2 total)