June 21, 2015

C program to Read From a File

#include <stdio.h>
#include <stdlib.h>
void main()
{
    FILE *fptr;
    char filename[15];
    char ch;
    printf("Enter the filename to be opened \n");
    scanf("%s", filename);
    /*  open the file for reading */
    fptr = fopen(filename, "r");
    if (fptr == NULL)
    {
        printf("Cannot open file \n");
        exit(0);
    }
    ch = fgetc(fptr);
    while (ch != EOF)
    {
        printf ("%c", ch);
        ch = fgetc(fptr);
    }
    fclose(fptr);
}

C Program to create and write a File

#include<stdio.h>
#include<conio.h>

int main()
{
FILE *fp;
char ch;
fp = fopen("one.txt", "w");
printf("Enter data");
while( (ch = getchar()) != EOF) {
    putc(ch,fp);
}
fclose(fp);

return 0;
}

Programming Manual

 

Star Formations http://cs-study.blogspot.com/2013/10/c-program-to-print-different-star.html
Hollow Square http://cs-study.blogspot.com/2013/10/c-program-to-print-hollow-stars-square.html
Ascending Order without loops http://cs-study.blogspot.com/2013/10/c-program-to-display-integers-in.html 
Phases of a Program  http://cs-study.blogspot.com/2013/09/c-program-phases-writing-and-executing.html
Dev C++ Installation  http://cs-study.blogspot.com/2013/09/installation-of-dev-c.html
Programming Introduction  http://cs-study.blogspot.com/2013/09/introduction-to-programming.html
Bubble Sort  http://cs-study.blogspot.com/2012/12/bubble-sort.html
Binary Search  http://cs-study.blogspot.com/2012/12/binary-search.html
Arrays  http://cs-study.blogspot.com/2012/10/arrays.html

C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...