Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовик6
.CPP/***************************************************************/
//Project work for Programming : First semester //
//Done by : Chiniah Aatish // //
//Group number : 1373 //
/**************************************************************/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<string.h>
//Functions are declared
char** Input_text(int);
void textout(char**,int);
char** obrabotka(char**,int);
void main(void)
{
int a,flag=0,obr_done=0;
char out='n',**text,**newtext={'\0'};
free(newtext);
free(text);
clrscr();
fflush(stdin);
do
{
clrscr();
fflush(stdin);
printf(" Choose any one of the menu points:\n");
printf("1 Input of original text.\n");
printf("2 Output of original text.\n");
printf("3 Processing of Text.\n");
printf("4 Output of processed text.\n");
printf("5 Help.\n");
printf("6 Exit.\n");
switch(getch())
{
case '1':
{ clrscr();
do
{
a=0;
fflush(stdin);
printf("Give the no. of lines in original text\n");
scanf("%d",&a);
if(a<=0)
{
printf("\nPlease enter a number from 1 to 32760\n");
printf("Press any key to continue");
getch();
clrscr();
}
}
while(a<=0);
flag=1;
text=Input_text(a);
}
break;
case '2':
{
if(flag==1)
{
clrscr();
printf("Here is the original text:\n");
textout(text,a);
}
else
printf("\n INPUT TEXT FIRST!!!\n");
getch();
}
break;
case '3':
{
if(flag==1)
{
clrscr();
newtext=obrabotka(text,a);
printf("\nThe original text:\n");
textout(text,a);
printf("\n\nThe processed text:\n");
textout(newtext,a);
obr_done=1;
}
else
printf("\n INPUT TEXT FIRST!!!\n");
getch();
}
break;
case '4' :{
if(flag==1)
{
if(obr_done==1)
{
clrscr();
printf("Here is the original text:\n");
textout(text,a);
printf("Here is the processed text:\n");
textout(newtext,a);
}
else
printf("\nProcess the text first\n");
}
else
printf("\n INPUT TEXT FIRST!!!\n");
getch();
}
break;
case '5':
{
printf("\nThe help screen\n");
printf("\nUsing the keyboard please input any number\n");
printf("from 1 to 6 to select your choice from\n");
printf("the menu and follow the instructions\n");
printf("given at each step\n");
getch();
}
break;
case '6':
{
printf("Confirm exit(Y/N)?\n");
fflush(stdin);
out=getch();
}
break;
default :
{
printf("\nPlease input a number from 1 to 4\n");
printf("Press any key to continue");
getch();
}
}
}
while(out!='y'&&out!='Y');
fflush(stdin);
clrscr();
}
////////////////////////////////////////////////////////////////////////////
/*
Function for output of texts
Inputed data
char **text //Data to be outputed
int a //nunber of lines
Returned value or data
void
function prototype
void textout(char **text,int a);
call example
textout(newtext,a);
*/
void textout(char **text,int a)
{
int i;
for(i=0;i<a;i++)
puts(text[i]);
}
////////////////////////////////////////////////////////////////////////////
/*
Function for input of original text
Inputed data
int a //nunber of lines
Returned value or data
char **text//inputed text
function prototype
char **Input_text(int a);
call example
text=Input_text(a);
*/
char* * Input_text(int a)
{
char s[130],**text;
int i;
text=(char**)malloc(a*sizeof(char*));
fflush(stdin);
for(i=0;i<a;i++)
{
printf("\nGive line no %d:\n",(i+1));
gets(s);
text[i]=(char*)malloc((strlen(s)+1)*sizeof(char));
strcpy(text[i],s);
}
return text;
}
////////////////////////////////////////////////////////////////////////////
/*
Function for processing of text
Inputed data
char **text//data to be processed
int a //nunber of lines
Returned value or data
char **newtext//processed text
function prototype
char **obrabotka(char** text,int a);
call example
newtext=obrabotka(text,a);
*/
char* * obrabotka(char **text,int a)
{
char data[130] = "\0";
char datanew[130] = "\0";
const char tokseps[] = "- .,;:#!?'{}[]";
char *pt1[130];
char badword[130],badword1[130],bad[130],*brok,*broke;
char** newtext;
char * datatk;
int wrdnum,b,exit,i,n;
char *pword;
clrscr();
char * pt;
newtext=(char**)malloc(a*sizeof(char*));
for(i=0;i<a;i++)
{
newtext[i]=(char*)malloc((130)*sizeof(char));
}
for(b=0;b<a;b++)
{
//printf("\nProcessing line no %d:\n\n",b+1);
datatk=text[b];
strcat(data,datatk);
//puts(data);
pt = strtok(data,tokseps);
//puts("\nThe broken down sentence is:\n");
i=0;
while(pt)
{
pt1[i]=pt;
//puts (pt);
pt = strtok(NULL, tokseps);
i++;
}
wrdnum=i-1;
//Inputing the word to be removed
exit=1;
if(b==0)
{
while(exit)
{
printf("\nPlease input a non-allowed word\n");
gets(badword);
strcpy(badword1,badword);
strcpy(bad,badword);
pword = strtok(badword,tokseps);
i=0;
while(pword)
{
if(i==0)
brok=pword;
pword = strtok(NULL, tokseps);
i++;
}
if(i==1&&strlen(badword1)==strlen(brok))
exit=0;
else
{
printf("\nPlease avoid punctuation and space in input\n");
printf("Press any key to continue");
getch();
clrscr();
}
}
do
{
printf("\nInput the number of space\n");
scanf("%d",&n);
if (n<=0 || n>20)
{
printf("\nPlease input a number between 1 to 20\n");
printf("Press any key to continue");
getch();
clrscr();
}
}
while(n<=0 || n>20);
memset(broke,' ',n);
broke = strcat(bad,broke);
//printf("broke = * %s *",broke);
}
//Producing the new and remove one of the word
i=0;
while(i<=wrdnum)
{
if(strcmp(pt1[i],badword)==0)
{
//puts("A word that is not allowed has been found");
strcat(datanew,broke);
strcat(datanew," ");
}
else
{
strcat(datanew,pt1[i]);
strcat(datanew," ");
}
//puts(datanew);
i++;
}
datatk=datanew;
// }
strcpy(newtext[b],datatk);//Output to final variable
//Initialising strings to zero
free(datatk);
data[0]='\0';
datanew[0]='\0';
free(datanew);
}
free(broke);
free(brok);
free(pword);
badword[0]='\0';
badword1[0]='\0';
bad[0]='\0';
return newtext;
}
Соседние файлы в предмете Программирование