hi i'm having two problems which i believe if i solve the first one the second will work(plus a little concern). i'm trying to write a program that opens a file(test.txt), and types Testing in it. at first it would give me an error when i ran it, i manually created the file and that solved the problem. now i'm trying to use fprintf to write to the file. but it won't work. i open the file after i run the program and its blank. because of that ofcourse i can't scan the file just to see whats inside it as a test. i'm trying two functions: fscanf and fgetc
using fscanf:and to use fgetc replaceCode:/* File I/O */ #include <stdio.h> int main() { FILE *test; char str[100]; test = fopen("c:\\test.txt", "w+"); fprintf(test, "Testing"); fscanf(test, "%s", str); fclose(test); printf("str: %s", str); getchar(); return 0; }withCode:fscanf(test, "%s", str);my to problems(summerized) are:Code:fgetc(str, 100, test)
1. why doesn't "w+" create the file?
2. why isn't fprintf write to the file?
my little concern is: getchar() is supposed to pause the program until i hit enter, why doesn't it work with some programs? like this one?