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個字元賦'