#include <stdio.h>
int openfile () //opens a file and saves the content in c
{
int c;
FILE *file;
file = fopen("File", "r"); /* looks for a File named "File" */
if (file == NULL)
{
printf("Error\n");
}
while(1) {
c = fgetc(file);
if(feof(file)) {
break;
}
printf("%c", c); /* This prints the contents of the file */
}
fclose(file);
return c;
}
int otherfunction1337() /* <- Problem: Why doesn't this add 10 and the
content of the file (in my example I wrote 20 into the file) */
{
int a = 10 + openfile(); /* ? */
printf("%i", a);
return 0;
}
int main (void)
{
otherfunction1337();
}
Thats what I got so far. Keep in mind that I tested this with a text file named "File". I just wrote "20" into it. I expected it to output the result of 20 + 10 (30) but it doesn't work.