Forum Replies Created
Viewing 2 posts - 1 through 2 (of 2 total)
- AuthorPosts
- LenoraRamseyParticipant
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.
1234567891011<br />#include<stdio.h><br />main()<br />{<br />long double a =0.0;<br />if(a>=(float)0.0)<br />printf("hi");<br />else<br />printf("hello");<br />}<br />It will prints hi.
1234567891011<br />#include<stdio.h><br />main()<br />{<br />long double a =0.1;<br />if(a>=(float)0.1)<br />printf("hi");<br />else<br />printf("hello");<br />}<br />It will prints hello.
I think now you can get the difference.
LenoraRamseyParticipantTry 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.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586<br />#include<stdio.h><br />#include<string.h><br />#include<stdlib.h><br />#include<limits.h><br /><br />char *reverse(char s[])<br />{<br />int c,i,j;<br /><br />for(i=0,j=strlen(s)-1;i<j;i++,j--)<br />{<br />c=s<i>;<br />s</i><i>=s[j];<br />s[j]=c;<br />}<br />return s;<br />}<br /><br /><br /><br />char *itoa(int n)<br />{<br />char s[100];<br />int i,sign,ind=0,mod,w=0;<br />if((sign=n)<0){<br />if(sign<=INT_MIN)<br />{<br />mod=-(n%10);<br />n=n/10;<br />ind=1;<br />}<br />n=-n;<br />}<br />i=0;<br />do<br />{<br />if(ind==1)<br />{<br />s[0]=mod+'0';<br />i++;<br />ind=0;<br />}<br />s[i++]=n%10+'0';<br /><br />}while((n/=10)>0);<br />s</i><i>='';<br />return (reverse(s));<br />}<br /><br />int exists(const char *filename)<br />{<br />FILE *f = fopen(filename, "r");<br />if (!f) return 0;<br />fclose(f);<br />return 1;<br />}<br /><br />int main ( )<br />{<br />char str [1024];<br />strcpy(str,"abcd");<br />int num = 0;<br />int created = 0;<br />while(created == 0)<br />{<br />num++;<br />if(exists(str))<br />{<br />char numb[100];<br />strcpy(str,"abcd");<br />strcpy(numb,"");<br />strcpy(numb,itoa(num));<br />strcat(str,numb);<br />}<br />else<br />{<br />FILE *f=fopen(str,"w");<br />printf("%s file createdn",str);<br />created=1;<br />fclose(f);<br />}<br />}<br />return 0 ;<br />}<br /></i> - AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)