大一c作业题,求助

题目:编写程序,功能是从键盘输入整数1234,一个字符a,一个实数5.6,用fprintf函数写入int.txt文件内。
我同学写的代码
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
char b;
float c;
FILE*fp;
scanf("%d,%c,%f",&a,&b,&c);
if((fopen("int.txt","w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
fprintf(fp,"%d,%s,%f",a,b,c);
fclose(fp);
return 0;
}
编译没问题,但执行完后int.txt文件可以创建,但是无法写入1234 a 5.6
我自个按照网课写的:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b;
char str[20],s[20];
float x,y;
FILE *fp;
scanf("%d %s %f",&a,str,&x);
if((fp=fopen("int.txt","w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
fprintf(fp,"%d %s %.1f",a,str,x);
fclose(fp);
return 0;
}
(请忽略没用的变量)
能执行,而且能写入数据。
求大佬解惑,第一个代码问题出在哪里?(好像我们两个的区别一个就是用字符,一个字符串,想不明白怎么回事)