C语言题求教

来源:百度知道 编辑:UC知道 时间:2024/05/25 03:29:43
累加a字符串各字符ASC码值,将累加和以格式%d写入到design1.dat

#include <stdio.h>
void main()
{ FILE *p; int s=0,i=0;
char *a="r235%^%34cdDW,.";
/*
*
*
* 在这里添加代码
*
*
*/
}

while('\0'!=*(a+i))
{
s+=*(a+i);
i++;
}

p=fopen("design1.dat","w");

if(NULL==p)
{
printf("Failed to open design1.dat, exit.");
exit(1);
}

fprintf(p, "%d", s);

if(fclose(p)==EOF)
{
printf("Failed to close design1.dat, exit.");
exit(1);
}

填进去就可以了。

#include <stdio.h>
int main(void)
{
FILE* p;
int s = 0, i = 0;
char* a ="r235%^%34cdDW,.";
while(a[i] != '\0')
{
s += (int)a[i];
i++;
}
p = fopen("design1.dat", "w");
if(p != NULL)
{
fprintf(p, "%d\n", s);
fclose(p);
}
return 0;
}

while(a[i]!='\0'){
s+=a[i];
i++;
}
if((p=fopen("design.dat","w+&q