@shady:i have a doubt. scanf returns number of succesfully read words. how come it will return -1?
On Sat, Jul 23, 2011 at 12:17 AM, geek forgeek <[email protected]> wrote: > @shady and @varun ... > i hav got it > thanx both of u :) > > On Fri, Jul 22, 2011 at 11:31 AM, shady <[email protected]> wrote: >> >> @aditi the problem is scanf returns -1(EOF value) when it encounters the >> end of file, and inspite of comparing the return value of scanf he is >> comparing value of character 'a' which is not correct.... >> therefore the for loop should be like this ::::::::::::::::::::::::: >> for(int t=scanf("%c",&a);t!=EOF;t=scanf("%c",&a)) >> what varun suggested is another way of doing it :) >> >> On Fri, Jul 22, 2011 at 11:41 PM, aditi garg <[email protected]> >> wrote: >>> >>> @shady. so in this case we shud use a!=-1 as the condition?? >>> >>> On Fri, Jul 22, 2011 at 11:37 PM, shady <[email protected]> wrote: >>>> >>>> you are scanning from stdin therefore it is not coming out of first for >>>> loop... because your terminating condition is for EOF, which is -1( scanf >>>> returns -1 ) at the end. >>>> >>>> On Fri, Jul 22, 2011 at 11:34 PM, shady <[email protected]> wrote: >>>>> >>>>> well you didn't mention the question, directly posted the code with no >>>>> head-tail... wait will answer, it is not coming out of first loop >>>>> >>>>> On Fri, Jul 22, 2011 at 11:26 PM, geek forgeek <[email protected]> >>>>> wrote: >>>>>> >>>>>> @shady this is nt a joke.. >>>>>> sorry if i am asking too stupid question >>>>>> i m getting an infinite loop here. >>>>>> not getting how? >>>>>> >>>>>> On Fri, Jul 22, 2011 at 10:40 AM, shady <[email protected]> wrote: >>>>>>> >>>>>>> what kind of joke is this ? >>>>>>> >>>>>>> On Fri, Jul 22, 2011 at 11:02 PM, geek forgeek >>>>>>> <[email protected]> wrote: >>>>>>>> >>>>>>>> #include<stdio.h> >>>>>>>> main() >>>>>>>> { >>>>>>>> FILE *fp; >>>>>>>> char a; >>>>>>>> fp=fopen("old.out","w"); >>>>>>>> if(fp==0) >>>>>>>> printf("File opening error"); >>>>>>>> else >>>>>>>> { >>>>>>>> for(scanf("%c",&a);a!=EOF;scanf("%c",&a)) >>>>>>>> fprintf(fp,"%c",a); >>>>>>>> fclose(fp); >>>>>>>> fp=fopen("old.out","r"); >>>>>>>> while(!feof(fp)) >>>>>>>> putchar(getc(fp)); >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> -- >>>>>>>> You received this message because you are subscribed to the Google >>>>>>>> Groups "Algorithm Geeks" group. >>>>>>>> To post to this group, send email to [email protected]. >>>>>>>> To unsubscribe from this group, send email to >>>>>>>> [email protected]. >>>>>>>> For more options, visit this group at >>>>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>>> >>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Algorithm Geeks" group. >>>>>>> To post to this group, send email to [email protected]. >>>>>>> To unsubscribe from this group, send email to >>>>>>> [email protected]. >>>>>>> For more options, visit this group at >>>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Algorithm Geeks" group. >>>>>> To post to this group, send email to [email protected]. >>>>>> To unsubscribe from this group, send email to >>>>>> [email protected]. >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >>> >>> -- >>> Aditi Garg >>> Undergraduate Student >>> Electronics & Communication Divison >>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY >>> Sector 3, Dwarka >>> New Delhi >>> 9718388816 >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
