You have bizarrely formatted code with many compilation errors.
Code:
$ gcc -Wall bar.c
bar.c: In function ‘Encryption’:
bar.c:30:3: warning: statement with no effect [-Wunused-value]
bar.c:30:3: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
bar.c:30:16: warning: incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
bar.c: In function ‘Decryption’:
bar.c:42:3: warning: statement with no effect [-Wunused-value]
bar.c:42:16: warning: incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
bar.c: In function ‘main’:
bar.c:60:5: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
bar.c:61:19: warning: comparison with string literal results in unspecified behavior [-Waddress]
bar.c:69:9: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
bar.c:69:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:78:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:84:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:96:11: warning: format not a string literal and no format arguments [-Wformat-security]
bar.c:108:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:115:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:121:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:133:11: warning: format not a string literal and no format arguments [-Wformat-security]
bar.c:145:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:152:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
bar.c:53:8: warning: unused variable ‘Char’ [-Wunused-variable]
Most of that is down to missing header files.
Here is your code.
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef int boolean;
#define true 1
#define false 0
char Shift(char Achar, int Shifts)
{
boolean Shiftleft = Shifts <= 0;
if (Shiftleft)
Shifts = -Shifts;
int Lowerbound = 32;
int Remainder;
int Upperbound = 126;
Remainder = Shifts % (Upperbound - Lowerbound);
if (Shiftleft) {
if (Remainder > (int) Achar - Lowerbound) {
return (char) (Upperbound + (((int) Achar - Lowerbound) - Remainder) + 1);
} else
return (char) ((int) Achar - Remainder);
} else {
if (Remainder > Upperbound - (int) Achar) {
return (char) (Lowerbound + (Remainder - (Upperbound - (int) Achar)) - 1);
} else
return (char) ((int) Achar + Remainder);
}
}
int Encryption(char *AString, char *Buffer)
{
int i = 0;
for (i; i != strlen(AString); i++) {
if ((int) AString[i] >= 32 && (int) AString[i] <= 126)
if (AString[i] != 10)
Buffer[i] = Shift(AString[i], i + 1);
}
Buffer[i] = '\0';
return 1;
}
int Decryption(char *AString, char *Buffer)
{
int i = 0;
for (i; i != strlen(AString); i++) {
if (AString[i] >= 32 && AString[i] <= 126)
if (AString[i] != 10)
Buffer[i] = Shift(AString[i], -i - 1);
}
Buffer[i] = '\0';
return 1;
}
int main(int argc, char *argv[])
{
char Char;
char Line[501], TLine[501];
TLine[0] = 0;
if (argc == 1 || argc == 2) {
printf("Useage : \n");
} else {
if (strcmp(argv[1], "-e") == 0 || strcmp(argv[1], "-d") == 0) {
if (argv[2] != "") {
char Temp[501];
if (strcmp(argv[1], "-d") == 0)
Decryption(argv[2], Temp);
if (strcmp(argv[1], "-e") == 0)
Encryption(argv[2], Temp);
printf("%s\n", Temp);
exit(0);
}
}
if (strcmp(argv[1], "-fe") == 0) {
FILE *Source, *Dest;
Source = fopen(argv[2], "r");
if (Source == NULL) {
printf("Error Opening The Source File.\n");
exit(1);
}
Dest = fopen(argv[3], "w");
//printf("File : %s\n",argv[2]);
if (Dest == NULL) {
printf("Error Opening The Destination File.\n");
exit(1);
}
char ch = 0;
int i = -1;
int EOFReached = 0;
while (EOFReached == 0) {
i++;
ch = fgetc(Source);
if ((ch == EOF) || (ch == '\n')) {
Line[i] = '\0';
Encryption(Line, TLine);
printf("%s||%s\n", Line, TLine);
fprintf(Dest, TLine);
fprintf(Dest, "\n");
Line[0] = 0;
TLine[0] = 0;
i = -1;
if (ch == EOF)
EOFReached = 1;
} else {
Line[i] = ch;
}
}
printf("\n");
exit(0);
}
if (strcmp(argv[1], "-fd") == 0) {
FILE *Source, *Dest;
Source = fopen(argv[2], "r");
if (Source == NULL) {
printf("Error Opening The Source File.\n");
exit(1);
}
Dest = fopen(argv[3], "w");
//printf("File : %s\n",argv[2]);
if (Dest == NULL) {
printf("Error Opening The Destination File.\n");
exit(1);
}
char ch = 0;
int i = -1;
int EOFReached = 0;
while (EOFReached == 0) {
i++;
ch = fgetc(Source);
if ((ch == EOF) || (ch == '\n')) {
Line[i] = '\0';
Decryption(Line, TLine);
printf("%s||%s\n", Line, TLine);
fprintf(Dest, TLine);
fprintf(Dest, "\n");
Line[0] = 0;
TLine[0] = 0;
i = -1;
if (ch == EOF)
EOFReached = 1;
} else {
Line[i] = ch;
}
}
printf("\n");
exit(0);
}
if (strcmp(argv[1], "-s") == 0) {
FILE *RFile;
RFile = fopen(argv[2], "r");
if (RFile == NULL) {
printf("Error Opening The File.\n");
exit(1);
}
char Char;
while ((Char = fgetc(RFile)) != EOF) {
printf("%c", Char);
}
}
}
printf("\n");
return 0;
}
With the right headers, the list is smaller.
Code:
$ gcc -Wall bar.c
bar.c: In function ‘Encryption’:
bar.c:32:3: warning: statement with no effect [-Wunused-value]
bar.c: In function ‘Decryption’:
bar.c:44:3: warning: statement with no effect [-Wunused-value]
bar.c: In function ‘main’:
bar.c:63:19: warning: comparison with string literal results in unspecified behavior [-Waddress]
bar.c:98:11: warning: format not a string literal and no format arguments [-Wformat-security]
bar.c:135:11: warning: format not a string literal and no format arguments [-Wformat-security]
bar.c:55:8: warning: unused variable ‘Char’ [-Wunused-variable]
bar.c:63:19: warning: comparison with string literal results in unspecified behavior [-Waddress]
You don't compare a string using != "" to find out if it's an empty string.
bar.c:98:11: warning: format not a string literal and no format arguments [-Wformat-security]
bar.c:135:11: warning: format not a string literal and no format arguments [-Wformat-security]
NEVER pass a raw string as the first parameter of printf style functions.
Use either puts(s) or printf("%s",s)
Code:
if (strcmp(argv[1], "-d") == 0)
Decryption(argv[2], Temp);
This is good.
Now make functions for your -fe, -fd and -s options as well, so that main() is a much tidier function.