A. c语言文件读取怎么弄
fp=fopen("*p","r");
改为
fp=fopen(p,"r");
B. C语言 统计衣服尺寸
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float a;
char s[][3] = {"S","M","L","XL"};
int b[4] = {0};
int n;
int i;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%f",&a);
if(a < 1.60)
b[0]++;
else if(a >= 1.60 && a< 1.70)
b[1]++;
else
if(a >= 1.70 && a < 1.80)
b[2] ++;
else
if(a >= 1.80)
b[3]++;
}
for(i = 0; i < 4; i++)
{
printf("%s %d\n",s[i],b[i]);
}
return 0;
}
C. c语言编程 某服装批发商店经营套装,也单价出售,若买的不少于50套,每套80元,不足50套每套10
#include "stdio.h"
int main(void)
{
int imoney = 0;
int iWaist = 0;
int itrousers = 0;
printf("请分别输入需要买的上衣和裤子的数目:");
scanf("%d%d" ,&iWaist ,&itrousers);//可以加上对输入数值的正确性的判断
if ( iWaist >= itrousers )
{
if ( itrousers >= 50 )
{
imoney = itrousers * 80 + ( iWaist - itrousers )*60;
}
else
{
imoney = itrousers * 100 + ( iWaist - itrousers )*60;
}
}
else
{
if ( iWaist >= 50 )
{
imoney = iWaist * 80 + ( itrousers - iWaist )*45;
}
else
{
imoney = iWaist * 100 + ( itrousers - iWaist )*45;
}
}
printf("monye = %d\n", imoney);
return 0;
}
D. C语言如何读取文件
一个c语言读写文件程序:
#include
"stdio.h"
#include
<stdlib.h>
main()
{
FILE
*fp1;//定义文件流指针,用于打开读取的文件
FILE
*fp2;//定义文件流指针,用于打开写操作的文件
char
text[1024];//定义一个字符串数组,用于存储读取的字符
fp1
=
fopen("d:\\a.txt","r");//只读方式打开文件a.txt
fp2
=
fopen("d:\\b.txt","w");//写方式打开文件a.txt
while(fgets(text,1024,fp1)!=NULL)//逐行读取fp1所指向文件中的内容到text中
{
puts(text);//输出到屏幕
fputs(text,fp2);//将内容写到fp2所指向文件中
}
fclose(fp1);//关闭文件a.txt,有打开就要有关闭
fclose(fp2);//关闭文件b.txt
}
E. c语言逐行读取文件
可以使用fgets函数。
1 函数名:
fgets
2 声明:
char *fgets(char *buf, int bufsize, FILE *stream);
3 头文件:
stdio.h
4 功能:
从文件结构体指针stream中读取数据,每次读取一行。读取的数据保存在buf指向的字符数组中,每次最多读取bufsize-1个字符(第bufsize个字符赋'