C examples for Pointer:Pointer Variable
Opens an existing file and changes one letters to an *, then prints the changed content.
#include <stdio.h> #include <stdlib.h> FILE * fptr;// ww w . j a v a 2 s . co m int main() { char letter; int i = 6; fptr = fopen("C:\\test\\letters.txt", "r+"); if (fptr == 0){ printf("There was an error while opening the file.\n"); exit(1); } // Seeks that position from the beginning of the file fseek(fptr, (i-1), SEEK_SET); // Subtract 1 from the position // because array starts at 0 // Write an * over the letter in that position fputc('*', fptr); // Now jump back to the beginning of the array and print it out fseek(fptr, 0, SEEK_SET); printf("Here is the file now:\n"); for (i = 0; i < 26; i++) { letter = fgetc(fptr); printf("The next letter is %c.\n", letter); } fclose(fptr); return(0); }