Please help! I’m trying to add score and name on a text file inC but I keep getting “File could not be opened”. Is my codewrong?
#include <stdio.h>
//int scores(unsigned int theScore);
int main(int argc, const char * argv[])
{
FILE *cfPtr = fopen_s(&cfPtr,”playerScores.txt”,”w”);
unsigned int scores;
char name[15];
if (cfPtr == NULL)
{
puts(“File could not beopened”);
}
else
{
puts(“Enter score and name.”);
fscanf_s(cfPtr,”%d%14s”,&scores, name);
while (!feof(cfPtr))
{
printf(cfPtr,”%s %lf “, name, scores);
}
fclose(cfPtr); //fclose closesfile
}
system(“pause”);
}
Expert Answer
An answer will be send to you shortly. .
PayPal Gateway not configured
PayPal Gateway not configured