Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by abc ( 16 years ago )
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX_STR 101

void promptUserForCodeFile&#40;char promptStr[],char fileName[],int size&#41;;
int readCodeFile&#40;FILE* fptr, char actualStr[], char codeStr[], int size&#41;;
void stringEncode(FILE* fInfile, FILE* fOutfile, char actualStr[], char codeStr[]);
char charEncode(char ch, char actualStr[], char codeStr[]);
void checkEncoding(char actualStr[], char codeStr[]);
int stringDup(char str[]);

int main(void)
{
int size;
char str[MAX_STR];
char str1[MAX_STR];
char str2[MAX_STR];
char actualStr[MAX_STR]; 
char codeStr[MAX_STR];
char fileName[MAX_STR];
FILE* fptr;
FILE* fpIn;
FILE* fpOut;
fpIn=fopen&#40;"fileName.txt","r"&#41;;
fpOut=fopen&#40;"fileName.txt","w"&#41;;

promptUserForCodeFile&#40;"Enter the code filename:",fileName,MAX_STR&#41;;
if(fpOut=fopen&#40;"fileName","w"&#41;);//open the same file for input
{
readCodeFile&#40;fptr,actualStr,codeStr,size&#41;;//if it opens call function 2
}
if(fpIn==NULL )//if the file did not open or invalid
{
printf("Wrong file selected or file not foundn");//print error message
return -1;//quit program
fclose(fpOut);//close this file before continuing
}

fpIn=fopen&#40;"fileName.txt","r"&#41;;//reads 2 more file names twice
promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;// call function 1 two times
promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;//call fucntion 1 two times
{
if(printf("Enter the name of the file to encode:n));
else
return -1;// find out how to write quit
{
else if
fprintf("Enter the name of the file to store the encoded data");//pass string size, how to write?
}
return -1;//she wanted us to use quit here

fgets(output,fileName, fileName,input);//reads 2 more file names
     promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;//calling the 1st function 2 times
   promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;//calling the 1st function 2 times
{
fprintf("Enter the name of the file to encode:n);
}
else
exit(1);//is this the correct way to write quit?
else if
{
printf("Enter the name of the file to store the encoded data");//pass string size, how to write?
}
else 
exit(1);//quit

while(fpOut=fopen&#40;"fileName.txt","r"&#41;//trying to open the 2 files this one for input
{
(fpOut=fopen&#40;"fileName.txt","w+"&#41;//trying to open the 2 files this one for output & input
if(fpIn==NULL || QUIT)//if either  of them do not open or quit
{
exit(100);//exit loop
}
}
OTHERWISE CONTINUE:
stringEncode(fInfile,fOutfile,actualStr,codeStr);//call function read from code file & write to encoded file
checkEncoding(actualStr,codeStr);//fucntion that checks if encoding worked
fclose(fpOut);

fgets(output,fileName.txt,fileName.txt,input);//reads 2 more file names
promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;//calling the 1st function 2 times
promptUserForCodeFile&#40;"Enter the code filename:",fileName,size&#41;;//calling the 1st function 2 times
{
fprintf("Enter the name of another file to encode:n);
}
else
exit(1);//is this the correct way to write quit?
else
{
fprintf("Enter the name of the file to store the encoded data");//pass string size, how to write?
}
else
QUIT;//quit
while(fpOut=fopen&#40;"fileName.txt","r"&#41;//trying to open the 2 files this one for input
{
(fpOut=fopen&#40;"fileName.txt","w+"&#41;//trying to open the 2 files this one for output & input
if(fpIn==NULL || QUIT)//if either  of them do not open or quit
{
exit(100);//exit loop
}

fclose(fpOut);
return 0;
}//end main

/*====================promptUserForCodeFile&#40;1&#41;==================================
Prints the prompt string. Reads into the string for the filename.
*/
void promptUserForCodeFile&#40;char promptStr[],char fileName[],int size&#41;;
{
printf("%s", promptStr);
fgets(fileName, size, stdin);//check
fileName[strlen(promptStr) -1] = '�'; //check
}

/*================================readCodeFile&#40;2&#41;===================================
Reads one line at a time to the end of the line. Checks if the lines are the same size and 
duplicat chars. Calls stringDup.
*/

int readCodeFile&#40;FILE* fptr,char actualStr[], char codeStr[],int size&#41;
{
fgets(actualStr,size, fptr);
fgets(codeStr, size, fptr);

if(strlen(actualStr != strlen(codeStr)) return -1);
(actualStr[size-1] && codeStr[size-1] == 'n')
  actualStr[size-1] && codeStr[size-1] = '�';
return (size-1);

if(stringDup(actualStr)) return 1;
if(codeDup(actualStr)) return 1;
return 0;
}
/*==========================stringEncode(3)=======================================
Encodes one char at a time to the end of the file to encode. Reads one char then calls
charFind to return the encoded char.
*/
void stringEncode(FILE* fInfile, FILE* fOutfile, char actualStr[], char codeStr[])
{
while((ch=fgetc(actualStr))!= EOF){
int fgetc(FILE*);
int fputc(int, FILE*);

if(fputc(ch,codeStr) == EOF){
return printf("An error has occured");
}
}
}

/*======================charEncode(4)========================================
Finds the char in the first string and returns the corresponding char in the 
second string. Uses  pointer parameter.
*/
char charEncode(char ch, char actualStr[], char codeStr[])
{
int index;

char index = while(actualStr, codeStr, ch);//check
return(codeStr[index]);
else
          return -1;
    }
/*========================checkEncoding(5)=================================
Decodes encoded file line by line. Uses rewind on files, ccompares decoded line to the corresponding
line in the file to encode. Prints decoded line next to encoded line if correct. Calls  charFind
 to decode a char and passes the code strings differently.
*/
void checkEncoding(char actualStr[], char codeStr[])
{
int length;
char inputLine;
char outputLine;
char decodeLine;

fgets!='n';
while(fgets(inputLine, actualStr,stdin);
 if(actualStr[length -1] == 'n')
actualStr[length -1] == '�';
return 0;

fgets(outputLine, codeStr);
if(codeStr[length -1] == 'n')
codeStr[length -1] == '�';
return 0;

if(strcmp(inputLine, outputLine) > 0)
printf("%s", inputLine);
else if(strcmp(inputLine ==outputLine)==0)
printf("%s",decodeLine);
rewind(fileName);
fputs(inputLine, actualStr);
if(codeStr[length -1] == 'n')
codeStr[length -1] == '�';
return 0;

if(stricmp(inputLine, outputLine) > 0)
{
inputLine==decodeLine;
}
else if(stricmp(inputLine ==outputLine)==0)
outputLine ==decodeLine;
         putc(decodeLine, stdin)

if(strcmp(decodeLine ==inputLine)
fgets(decodeLine, inputLine);
while(fgets(decodeLine, outputLine)
int strlcmp(const* str1, const char* str 2)
while(tolower(*str1) == tolower(*str2) && *str1 !='�')
++str1;
++str2;
return tolower(*str1) - tolower(*str2);

charFind(actualStr[],codeStr[])
fgets(index, actualStr, stdin);
if(strcmp(actualStr[], codeStr[]) ==0)
return index;
else if(strcmp(actualStr[], codeStr[]) !=0)
return index -1;

}
/*=========================stringDup(6)==================================
Checks one string. If duplicates are found returns 1 or 0 for no duplicates.

*/
int stringDup(char str[])
{

int i;
int j;

  for (i=0; i<str; i++)
  {
for(j=0; j<str;j++)
{
return 1;
else
  }
   return 0;
}

return 1;
}

 

Revise this Paste

Your Name: Code Language: