First, get a compiler which will warn you when you screw up printf/scanf formats.
Eg.
Code:
$ gcc -Wall bar.c
bar.c: In function ‘main’:
bar.c:35: warning: format ‘%c’ expects type ‘char *’, but argument 3 has type ‘int *’
bar.c:37: warning: format ‘%c’ expects type ‘char *’, but argument 3 has type ‘int *’
bar.c:52: warning: too few arguments for format
bar.c:54: warning: too few arguments for format
bar.c:19: warning: unused variable ‘chars’
bar.c:13: warning: unused variable ‘exit’
bar.c:36: warning: ‘columns’ may be used uninitialized in this function
bar.c:34: warning: ‘rows’ may be used uninitialized in this function
Second, improve your indent style, say something like this
Code:
#include <stdio.h>
char inversion(char image[][200], char chars[], int rows, int columns);
char translation(char image[][200], int up, int right);
char rotate(char image[][200], int rows, int columns);
char shrink(char image[][200], int rows, int columns);
int main()
{
int i = 0;
int j = 0;
int choice;
int exit = 0;
int rows;
int columns;
int junk;
char image[80];
char chars[12] =
{ 'M', 'W', 'B', 'H', 'A', 'S', 'I', '+', ';', ',', '.' };
FILE *inputr; //input file pointer
FILE *outp; //output file pointer
printf("Please enter file name: ");
//ATTEMPT TO OPEN FILE!
scanf("%s", image);
if ((inputr = fopen(image, "r")) == NULL) { //if file cannot open
printf("Could not open image.txt\n");
return 1;
} //end if
else { //if file opens
for (i = 0; i < rows; i++) {
fscanf(inputr, "%c", &junk);
for (j = 0; j < columns; j++) {
fscanf(inputr, "%c", &junk);
} //end inner for loop
} //end outer for loop
fclose(inputr); //close file when done reading it
////fscanf to read in, also do print
} //end else
//ATTEMPT TO CREATE A NEW FILE!
if ((outp = fopen("finalimage.txt", "w")) == NULL) { //if file cannot be created
printf("Could not open output.dat\n");
return 1;
} //end if
else { //if file creation is successful
for (i = 0; i < rows; i++) {
fprintf(outp, "%c");
for (j = 0; j < columns; j++) {
fprintf(outp, "%c");
} //end inner for
} //end outer for
fclose(outp); //close file when done writing it
} //end else
///print array to a new file
printf("Would you like to:\n\n");
printf("1. Inversion\n");
printf("2. Translation\n");
printf("3. Rotate\n\n");
printf("4. Shrink-by-2");
scanf("%d", &choice);
if (choice > 4 || choice < 1) { /*Stops any possible input that would not process in the program */
printf("Invalid Entry, try again");
scanf("%d", &choice);
} //end if
return 0;
} //end the main