ya, you are right, but it returns -1 when it reaches the end of file. On Sat, Jul 23, 2011 at 9:15 AM, arun kumar <kumar0...@gmail.com> wrote:
> @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 <geekhori...@gmail.com> > wrote: > > @shady and @varun ... > > i hav got it > > thanx both of u :) > > > > On Fri, Jul 22, 2011 at 11:31 AM, shady <sinv...@gmail.com> 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 <aditi.garg.6...@gmail.com > > > >> wrote: > >>> > >>> @shady. so in this case we shud use a!=-1 as the condition?? > >>> > >>> On Fri, Jul 22, 2011 at 11:37 PM, shady <sinv...@gmail.com> 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 <sinv...@gmail.com> 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 < > geekhori...@gmail.com> > >>>>> 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 <sinv...@gmail.com> wrote: > >>>>>>> > >>>>>>> what kind of joke is this ? > >>>>>>> > >>>>>>> On Fri, Jul 22, 2011 at 11:02 PM, geek forgeek > >>>>>>> <geekhori...@gmail.com> 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 algogeeks@googlegroups.com. > >>>>>>>> To unsubscribe from this group, send email to > >>>>>>>> algogeeks+unsubscr...@googlegroups.com. > >>>>>>>> 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 algogeeks@googlegroups.com. > >>>>>>> To unsubscribe from this group, send email to > >>>>>>> algogeeks+unsubscr...@googlegroups.com. > >>>>>>> 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 algogeeks@googlegroups.com. > >>>>>> To unsubscribe from this group, send email to > >>>>>> algogeeks+unsubscr...@googlegroups.com. > >>>>>> 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 algogeeks@googlegroups.com. > >>>> To unsubscribe from this group, send email to > >>>> algogeeks+unsubscr...@googlegroups.com. > >>>> 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 algogeeks@googlegroups.com. > >>> To unsubscribe from this group, send email to > >>> algogeeks+unsubscr...@googlegroups.com. > >>> 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 algogeeks@googlegroups.com. > >> To unsubscribe from this group, send email to > >> algogeeks+unsubscr...@googlegroups.com. > >> 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 algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.