Вы находитесь на странице: 1из 5

#include <stdio.

h>
#include <stdlib.h>

void main ()
{
FILE *fp, *fp1;
char fn[20], c;
printf( "\nEnter filename for reading" );
scanf( "%s", fn );
fp = fopen( fn, "r" );
if ( fp == NULL )
{
printf( "File can't be opened" );
exit ( 0 );
}
printf( "\nEnter filename for writing" );
scanf( "%s", fn );
fp1 = fopen( fn, "w+" );
if ( fp1 == NULL )
{
printf( "\nFile can't be opened" );
exit ( 0 );
}
c = fgetc( fp );
while( c != EOF )
{
if ( c == ' ' )
{
fputc ( c, fp1 );
while ( c == ' ' )
{
c = fgetc( fp );
}
}

if ( c == '"' )
{
//fputc( c, fp1 );
while( c != '"' )
{
fputc( c, fp1 );
c = fgetc( fp );
}
//fputc( c, fp1 );

}
/*if ( c == '\n' )
{
while ( c == '\n' )
{
c = fgetc( fp );
}
}
fputc( c, fp1 );
c = fgetc( fp );*/
if ( c != EOF )
{
fputc( c, fp1 );
c = fgetc( fp );
}
}
fclose( fp );
fclose( fp1 );
}
#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *f1, *f2;
char file1[100], file2[100], c;
scanf("%s", file1);
scanf("%s", file2);
f1=fopen(file1, "r");
f2=fopen(file2, "w+");
if(f1 && f2)
{
c=fgetc(f1);
while(c!=EOF)
{
if(c==' '|| c=='\t')
{
if(c==' ')
fputc(c, f2);
c=fgetc(f1);

while(c!=EOF && (c==' ' || c=='\t'))


c=fgetc(f1);
}
else
{
fputc(c, f2);
c=fgetc(f1);
}
}
}
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
int start=1;
printf("Enter the filename to open for reading: ");
scanf("%s", filename);
fptr1 = fopen(filename, "r");
if (fptr1 == NULL)
{
printf("Cannot open file %s", filename);
exit(0);
}
printf("Enter the filename to open for writing: ");
scanf("%s", filename);
fptr2 = fopen(filename, "w+");
int flag=0;
start=1;
c = fgetc(fptr1);
while (c != EOF)
{
if(c == '#')
{

if(start == 1)
flag=1;
else
{
fputc(c,fptr2);
start=0;
}
}
else
{
if(c == '/')
flag =0;
if (!(c==' '))
start =0;
if(c=='\n')
{
start=1;
flag=0;
}
if(!flag)
{
fputc(c,fptr2);
}
}
c = fgetc(fptr1);

}
fclose(fptr1);
}
#include <stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main()
{
FILE *fp;
char c;
printf("enter the filename\n");
char compare[200];
char string[200];
scanf("%s",string);
fp=fopen(string,"r");
c=getc(fp);
int count=0;
int l;
int index=0;
char
key[][20]={"if","else","for","int","double","float","short","long","void"
,"main","while","switch","case","do","include","printf","scanf"};
while(c!=EOF)
{
if(c=='('|| c==' '||c=='\n')
{
for(int i=0;i<16;i++)
{
if(strcmp(compare,key[i])==0)
{
l = strlen(key[i]);
for ( int j = 0; j < l; j++ )
{
printf("%c",key[i][j] - 32);
}
printf("\n");
break;
}
}
memset(compare,0,sizeof(compare));
count=0;
index=0;
}
else if (c!='\t')
{
compare[index++]=c;

}
c=getc(fp);
}
}

Вам также может понравиться