sorry i pasted wrong questn unser 2..

the real question is
which file will get closed through fclose()
#include<stdio.h>
int main()
{
FILE *fp,*fs,*ft;
fp=fopen("a.c","r");
fs=fopen("b.c","r");
ft=fopen("c.c","r");
fclose(fp,fs,ft);
return 0;
}

3. yes it is feof..srry typed it wrong... nd fgets(str,80,fp) is perfectly
fine.. now the ans to this questn is that last line of the file will be
printed twice...( which i m unable to get why)...plzz explain...

@ souravsain plzz ignore this mail..srry for the inconvenience..

On 13 June 2010 17:37, jalaj jaiswal <jalaj.jaiswa...@gmail.com> wrote:

> in question 1... ch gets the value of EOF... so first kicit 44-a
> gokulpeth\0 nagpur will get printed and then the value of EOF..
>
>  question number 2 .. seems to me as nrml ...i think myfile.c only gets
> closed
>
> in question number 3..it shld be fgets(str,79,fp)
>
>
> On Sun, Jun 13, 2010 at 2:49 PM, divya <sweetdivya....@gmail.com> wrote:
>
>> 1. wat ll be the o/p. plz explain y?
>> // abc.c contains "kicit 44-a gokulpeth\0 nagpur"
>> #include<stdio.h>
>>  #include<stdlib.h>
>>  int main()
>>  {
>>  unsigned char ch;
>>  FILE *fp;
>>  fp=fopen("abc.c","r");
>>  if(fp==NULL)
>>  {
>>  printf("unable to open the file \n");
>>  exit(1);
>>  }
>>  while((ch=getc(fp))!=EOF)
>>  printf("%c",ch);
>>  fclose(fp);
>>  printf("\n",ch);
>>  return 0;
>>  }
>>
>>  2.which file will get closed through fclose() in the following
>> program and why?
>> #include<stdio.h>
>>          int main()
>>  {FILE *fp;
>>  char ch;
>>  int i=1;
>>  fp=fopen(myfile.c","r");
>>          while((ch=getc(fp)!=EOF))
>>          {
>>                  if(ch=='\n')
>>                          i++;
>>          }
>>
>>          fclose(fp);
>>          return 0;
>>  }
>>
>>  3.point out the error if any in following
>>
>> #include<stdio.h>
>>          int main()
>>  {
>>          FILE *fp;
>>          char str[80];
>>          fp=fopen("trial","r");
>>          while(!eof(fp))
>>          {
>>                  fgets(str,80,fp);
>>                  puts(str);
>>          }
>>          fclose(fp);
>>          return 0;
>>  }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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.

Reply via email to