|  #include <stdio.h> | 
| int
               
               
               ungetc (int c, FILE *stream); | 
One character of push-back is guaranteed, but as long as there is sufficient memory, an effectively infinite amount of pushback is allowed.
If a character is successfully pushed-back, the end-of-file indicator for the stream is cleared. The file-position indicator is decremented by each successful call to ungetc; if its value was 0 before a call, its value is unspecified after the call.
/****************** this pushing character to file stream using ungetc **************/
#include <stdio.h>
int main(void)
{
        int c;
        FILE* fp = fopen("c:\\input.txt", "w");
        fprintf(fp, "%s", "abcdefghijklmn");
        fprintf(fp, "%c", '\n');
        fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
        fclose(fp);
        char * name = "C:\\input.txt";
        fp = fopen(name, "w+");
        if (fp == NULL)
                {
                printf ("fopen failed\n");
                return -1;
                }
        if(ungetc('a',fp)!='a') printf("ungetc failed\n");
        
        fseek(fp,-1,SEEK_CUR);
        c=getc(fp);
        printf("character read from stream is \"%c\"\n",c);
        fclose(fp);
}
         
      Output
 character read from stream is "a"
         
      
| © 2005-2007 Nokia |