kemaren baru saja saya share program C untuk baca file, kali ini saya akan memberikan program COBOL untuk baca file, berikut adalah listingnya :
IDENTIFICATION DIVISION.
PROGRAM-ID. SR.
AUTHOR. JUNIOR.
DATE-WRITTEN. 04-11-2012.
DATE-COMPILED. 04-11-2012.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DEPARTS ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL
FILE STATUS IS OUT.
DATA DIVISION.
FILE SECTION.
FD DEPARTS
LABEL RECORD IS STANDARD
VALUE OF FILE-ID IS 'AIRLINES.txt'
DATA RECORD IS DEPARTLIST.
01 DEPARTLIST.
02 A PIC X(3).
02 CODES PIC X(9).
02 B PIC X(3).
02 DESTIN PIC X(7).
02 C PIC X(3).
02 TIM PIC X(5).
WORKING-STORAGE SECTION.
77 OUT PIC XX.
01 DEPARTS-OUT.
02 A-OUT PIC X(3).
02 CODES-OUT PIC X(9).
02 B-OUT PIC X(3).
02 DESTIN-OUT PIC X(7).
02 C-OUT PIC X(3).
02 TIM-OUT PIC X(5).
01 GARIS PIC X(34) VALUE ALL '-'.
SCREEN SECTION.
01 HAPUS.
02 BLANK SCREEN.
01 JUDUL.
02 LINE 4 COLUMN 2 '| LIST OF DEPARTURES |'.
02 LINE 5 COLUMN 2 PIC X(34) USING GARIS.
02 LINE 6 COLUMN 2 '| PLANE-CODE DESTINATION TIME |'.
02 LINE 7 COLUMN 2 PIC X(34) USING GARIS.
PROCEDURE DIVISION.
BUKA-FILE.
OPEN INPUT DEPARTS.
MULAI.
DISPLAY HAPUS.
MOVE 8 TO LIN.
DISPLAY JUDUL.
BACA.
READ DEPARTS INTO DEPARTS-OUT
AT END GO TO SELESAI.
TAMPILKAN.
DISPLAY (LIN, 2) DEPARTS-OUT,
ADD 1 TO LIN.
GO TO BACA.
SELESAI.
DISPLAY (LIN, 2) GARIS.
CLOSE DEPARTS.
STOP RUN.
Saturday, January 5, 2013
Program C untuk membaca semua file di dalam suatu folder
Berikut ini adalah program C yang berguna untuk melakukan seleksi secara otomatis terhadap abstrak paper yang ada di suatu folder "Files". Hasil seleksi akan otomatis masuk ke dalam txt baru yang bernama "Result.txt". Dan juga program ini akan menghitung jumlah kata dan ada tidaknya keyword di dalam abstrak tersebut dan semua itu tergantung oleh tema dari abstrak itu sendiri. Berikut adalah listing programnya :
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <conio.h>
int main(void) {
int args = 0;
char lokasi[64] = "Files\\";
DIR *directory;
struct dirent *ep;
directory = opendir(lokasi);
FILE *fp,*dt;
char str1[80];
char Skey1[10]="visual";
char Skey2[10]="tradition";
char Skey3[10]="animals";
char Skey4[10]="relations";
int Itheme;
int Istats=0;
int Iword=1;
int Imin;
if (directory != NULL)
{
while (args != 2)
{
ep = readdir(directory);
args++;
}
args = 1;
while (ep = readdir(directory))
{
system("cls");
char lokasi[64] = "Files\\";
int Istats=0;
int Iword=1;
fp = fopen(strcat(lokasi, ep->d_name),"r");
printf("***Abstract checker program***");
printf("\n**Junior Lie-SMTI06-53411891**");
printf("\nThe file name is [%s] ",ep->d_name);
printf("\nEnter the theme : ");
printf("\n1. Arts ");
printf("\n2. Humanities ");
printf("\n3. Science");
printf("\n4. SocialScience\n");
scanf("%d",&Itheme);
if(Itheme==1){Imin=150;}
else if(Itheme==2){Imin=250;}
else if(Itheme==3){Imin=220;}
else if(Itheme==4){Imin=200;}
dt = fopen("Reply.txt", "a");
rewind(fp);
while (!feof(fp))
{
fscanf(fp, "%s",str1);
Iword++;
if(Itheme==1){if((strstr(str1,Skey1))!=NULL){Istats=1;}}
else if(Itheme==2){if((strstr(str1,Skey2))!=NULL){Istats=1;}}
else if(Itheme==3){if((strstr(str1,Skey3))!=NULL){Istats=1;}}
else if(Itheme==4){if((strstr(str1,Skey4))!=NULL){Istats=1;}}
}
printf("\nWords : %d",Iword);
printf("\nMinimum words : %d",Imin);
if(Itheme==1){printf("\nThe keyword for this theme is \"%s\"",Skey1);}
else if(Itheme==2){printf("\nThe keyword for this theme is \"%s\"",Skey2);}
else if(Itheme==3){printf("\nThe keyword for this theme is \"%s\"",Skey3);}
else if(Itheme==4){printf("\nThe keyword for this theme is \"%s\"",Skey4);}
printf("\nThe file was successfully checked. Check Reply.txt for the result\n");
fclose(fp);
if (Iword < Imin){
fprintf(dt,"\n%s - Sorry we have rejected your abstract, as the number of words that are not eligible \n",ep->d_name);
}
else if(Istats==0){
fprintf(dt,"\n%s - Sorry we have rejected your abstract, because it does not contain the keyword \n",ep->d_name);
}
else{
fprintf(dt,"\n%s - Congratulations! We have approved your abstract !",ep->d_name);
}
fclose(dt);
args++;
getch();}
closedir(directory);
}
else
{
printf("Directory not found!");
}
}
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <conio.h>
int main(void) {
int args = 0;
char lokasi[64] = "Files\\";
DIR *directory;
struct dirent *ep;
directory = opendir(lokasi);
FILE *fp,*dt;
char str1[80];
char Skey1[10]="visual";
char Skey2[10]="tradition";
char Skey3[10]="animals";
char Skey4[10]="relations";
int Itheme;
int Istats=0;
int Iword=1;
int Imin;
if (directory != NULL)
{
while (args != 2)
{
ep = readdir(directory);
args++;
}
args = 1;
while (ep = readdir(directory))
{
system("cls");
char lokasi[64] = "Files\\";
int Istats=0;
int Iword=1;
fp = fopen(strcat(lokasi, ep->d_name),"r");
printf("***Abstract checker program***");
printf("\n**Junior Lie-SMTI06-53411891**");
printf("\nThe file name is [%s] ",ep->d_name);
printf("\nEnter the theme : ");
printf("\n1. Arts ");
printf("\n2. Humanities ");
printf("\n3. Science");
printf("\n4. SocialScience\n");
scanf("%d",&Itheme);
if(Itheme==1){Imin=150;}
else if(Itheme==2){Imin=250;}
else if(Itheme==3){Imin=220;}
else if(Itheme==4){Imin=200;}
dt = fopen("Reply.txt", "a");
rewind(fp);
while (!feof(fp))
{
fscanf(fp, "%s",str1);
Iword++;
if(Itheme==1){if((strstr(str1,Skey1))!=NULL){Istats=1;}}
else if(Itheme==2){if((strstr(str1,Skey2))!=NULL){Istats=1;}}
else if(Itheme==3){if((strstr(str1,Skey3))!=NULL){Istats=1;}}
else if(Itheme==4){if((strstr(str1,Skey4))!=NULL){Istats=1;}}
}
printf("\nWords : %d",Iword);
printf("\nMinimum words : %d",Imin);
if(Itheme==1){printf("\nThe keyword for this theme is \"%s\"",Skey1);}
else if(Itheme==2){printf("\nThe keyword for this theme is \"%s\"",Skey2);}
else if(Itheme==3){printf("\nThe keyword for this theme is \"%s\"",Skey3);}
else if(Itheme==4){printf("\nThe keyword for this theme is \"%s\"",Skey4);}
printf("\nThe file was successfully checked. Check Reply.txt for the result\n");
fclose(fp);
if (Iword < Imin){
fprintf(dt,"\n%s - Sorry we have rejected your abstract, as the number of words that are not eligible \n",ep->d_name);
}
else if(Istats==0){
fprintf(dt,"\n%s - Sorry we have rejected your abstract, because it does not contain the keyword \n",ep->d_name);
}
else{
fprintf(dt,"\n%s - Congratulations! We have approved your abstract !",ep->d_name);
}
fclose(dt);
args++;
getch();}
closedir(directory);
}
else
{
printf("Directory not found!");
}
}
Subscribe to:
Posts (Atom)