However, I also have to export it to a .txt file. I'm struggling with this. I tried manually creating a file, and that stopped my program from even opening to execute. I tried just writing it to a .txt file instead of a .dat, but every time I try to compile it that way, it comes up with an error. (Specifically, it says ld.exe will not allow the program to execute.)
I'm really new to this, so any help or tips would be very appreciated.
#include <stdio.h>
int main(void)
{
int recordnumber;
char toolname[30];
int quantity;
double cost;
FILE *cfPtr;
if ((cfPtr = fopen("hardware.dat", "w")) == NULL )
{
printf("File could not be opened.\n");
}
else
{
printf("Enter the record number, tool name, quantity, and cost.\n");
printf("Enter EOF to end input.\n");
printf("?");
scanf("%d%s%d%lf", &recordnumber, toolname, &quantity, &cost);
while (!feof(stdin))
{
fprintf(cfPtr, "%d %s %d %.2f\n");
printf("?");
scanf("%d%s%d%lf", &recordnumber, toolname, &quantity, &cost);
}
fclose(cfPtr);
}
return 0;
}

New Topic/Question
Reply



MultiQuote





|