What is the character between the two single quote marks in the first call
to memset?  My email shows no character (the quotes are adjacent) and C does
not support an empty character constant.  Perchance did you have a hex 00
there?  If so, the code would be more readable using '\0' as the character
constant.

The second call to memset serves no purpose because the ensuing call to
fread will completely replace the contents of buffer (or fail).

You never copy your input data from buffer to buffout so the question is
what data were expecting file.data to contain for fread to obtain?

Your call to fgets will also have problems.  It will read at most 79
characters into buffer.  If a '\n' occurs anywhere within those 79, it is
placed in buffer and no more data is transferred.  In any event, after the
last character is read (either the 79th, the '\n', or the last character in
the dataset pointed to by the TEST1 DD statement) fgets will place a string
terminating '\0' in buffer.  This means you can never see the 80th character
in each record of your input.

I don't know if you intended this but you increment wctr twice for each
record you read.  The fact that you don't initialize either rctr or wctr
before incrementing them means that both will have indeterminate values.

If fread fails for any reason, including end of file, the loop will
terminate.  The feof test will not execute in this case.  Therefore, the
feof test will always return 0 whenever it executes and is therefore
useless.

:>: -----Original Message-----
:>: From: IBM Mainframe Discussion List [mailto:[email protected]] On
:>: Behalf Of Scott Ford
:>: Sent: Friday, May 10, 2013 1:04 PM
:>: To: [email protected]
:>: Subject: C question -- not sure where to ask it
:>:
:>: All:
:>:
:>: I am writing a routing and want to use type=memory files in C and this
:>: is what i tried...
:>:
:>:
:>:   char buffer[80];
:>:   char buffout[80];
:>:   char lineout[121];
:>:   int rctr;
:>:   int wctr;
:>:   fobj = fopen("file.data","w,type=memory");
:>:   if(fobj != NULL)
:>:       printf("FOBJ  File Open at: %s\n",time_of_day_now);
:>:   rdr = fopen("DD:TEST1","r,blksize=80,recfm=f");
:>:   if(rdr != NULL)
:>:       printf("TEST1 File Open at: %s\n",time_of_day_now);
:>:     while(fgets(buffer,80,rdr) != NULL)
:>:       {
:>:          rctr++;
:>:          printf("rec %i %s\n",rctr,buffer);
:>:          wctr++;
:>:          memset(buffout,'',sizeof(buffout));
:>:          strcpy(buffout,"\n");
:>:          fwrite(buffout,1,80,fobj);
:>:          wctr++;
:>:       }
:>:          fclose(rdr);
:>:          fclose(fobj);
:>:          printf("TEST1 File closed at: %s\n",time_of_day_now);
:>:          printf("FOBJ  File closed at: %s\n",time_of_day_now);
:>:          printf("TEST1 records read:    %i\n",rctr);
:>:          printf("TEST1 records written: %i\n",wctr);
:>:          rctr = 0;
:>:          fobj = fopen("file.data","r,type=memory");
:>:          memset(buffer,' ',sizeof(buffer));
:>:          while(fread(buffer,80,1,fobj) == 1)
:>:          {
:>:             rctr++;
:>:             printf("rec %i %s\n",rctr,buffer);
:>:            if (feof(fobj))
:>:              {
:>:                   break;
:>:              }
:>:          }
:>:          fclose(fobj);
:>: }
:>:
:>: The fread is yielding no output just spaces ...so i must be
:>: misunderstanding something
:>: Can someone be so kind as to shed some light on this for me ..

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to