Use a file pointer name in another file it was not declared in.
I want to use a file pointer name in another file it is not declared in using a makefile. I tried searching for it but I only found how to use normal variables and not file pointer names.
I tried just running it through the makefile I wrote for the commands and used the file pointer name as I would normally do but it said it was not declared because I didn't declare it in that specific file but I did declare it in the second C file.
This is the main file:
#include"cube.h"
#include <stdio.h>
int main() {
char encdec;
char fname[30];
char foutname[30];
printf("Write e for encode or d for decode\n");
scanf("%c", &encdec);
printf("Enter file name\n");
scanf("%s", fname);
printf("Enter output file name\n");
scanf("%s", foutname);
FILE* read = fopen(fname, "r");
FILE* code = fopen(foutname, "w");
char c;
if (read == NULL) {
printf("Error! opening file");
return 0;
}
if (encdec == 'e' || encdec == 'E') {
while ((c = fgetchar()) != EOF) {
encode();
}
}
}
and this is the second file I want to use the file pointers from the main file:
int encode() {
const int d = 10;
if (c >= 'a' && c + d < 'z' || c >= 'A' && c + d < 'Z') {
fprintf(code, "%c\n", c + d);
}
else if (c < 'A' || 'a'>c > 'Z' || c > 'z') {// making sure the input
is
within the alphabets
fprintf(stdout, "invalid character\n");
}
else if (c + d > 'z') {
c = ((c + d) % 122) + 96;/*using the ascii equivalent of the
letters for it to stay in the range of the alphabet we want it
to
be*/
fprintf(code, "%c\n", c);
}
else if (c + d > 'Z' < 'a') {
c = ((c + d) % 90) + 64;
fprintf(code, "%c\n", c);
}
}