Hello,
As I'am new to c and tried already to search on the web, I was thinking to ask here.
I'am trying to write a char Array to a File, but for some reasons the char seems empty.
I don't know if it depends on getting the Input or writing it to the the File.
I tried some different codes to write it to a File (it's not the whole code):
if(fgets(nVal,BUF,stdin) == NULL) {
printf("Wrong Input\n");
} // Input for the Array
printf("%s",nVal); // printout as test, is empty
fp = fopen(DATAFILE,"w+"); // open the File
//for (int i = 0; i < sizeof (nVal) / sizeof(nVal); i++) {
//fprintf(fp, "%s", nVal[i]);
//} // Test one, is empty
//if(fwrite(&nVal, sizeof(nVal), 1, fp) != 1) {
//fprintf(stderr, "Write Error in %s\n", DATAFILE);
//fclose(fp);
//return;
//} // Test two, writes some random Stuff
fprintf(fp, "%s\n", nVal); // Test three, is empty
Where might be the Problem ?
Thanks