+ 2

What is wrong in this programming?

#include <stdio.h> int main() { int id,sa; char na; FILE *fp; fp=fopen("file.text","w"); printf("enter staff name,salary and id"); scanf("%s%d%d",na&sa&id); fprintf(fp,"%s\t%d\t%d\n,na,sa,id"); fclose(fp); return 0; }

2nd Jan 2022, 2:48 AM
Ganesh Neupane
Ganesh Neupane - avatar
2 Respuestas
+ 3
Your scanf line doesn't have commas between variables. Your fprintf line seems to have the variables inside the quotation marks. Your fclose line has (fopen("file.text","w")) as it's argument, is that correct? Does C behave like Python when opening files? Should you use something like while/try when opening files?
2nd Jan 2022, 4:10 AM
HungryTradie
HungryTradie - avatar
+ 4
What are the expected and actual results?
2nd Jan 2022, 3:41 AM
Emerson Prado
Emerson Prado - avatar