Hello, I keep getting a segmentation error in this code
I'm trying to get two values (from two lines) in a seperate out file, set them equal to a value, and then use them for calculations. But I cant really get that far. Any help?
Code:
-bash-3.00$ ./a.out
Name: My Name
str1 = (null)
Segmentation fault
-bash-3.00$
Code:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
void displayName(void);
bool openFile(FILE *fIn, FILE *fOut);
int main(void) {
FILE *fIn, *fOut;
displayName();
openFile(fIn, fOut);
return 0;
}
void displayName(void) {
printf("\nName: My Name\n\n");
}
bool openFile(FILE *fIn, FILE *fOut) {
int str1, str2;
if ((fIn = fopen("test.txt", "r")) != NULL) {
if ((fOut = fopen("out.txt", "w")) != NULL) {
fscanf(fIn, "%s\n%s", str1, str2);
printf("\nstr1 = %s", str1);
printf("\nstr2 = %s", str2);
}
else
printf("\nUnable to open \"out\" for writing.");
fclose(fIn);
}
else
printf("\nUnable to open \"test\" for reading.");
}