标签:文件 turn 转换 logs == blog int 关闭 str
#include <stdio.h>
#include <string.h>
long fun ( char *p)
{
int len,t;
long x=0;
len=strlen(p);
if(p[0]==‘-‘)
{t=-1;len--;p++;}
else t=1;
while(*p)
x=10*x+(*p-48),p++;
return x*t;
}
main() /* 主函数 */
{ char s[6];void NONO ();
long n;
printf("Enter a string:\n") ;
gets(s);
n = fun(s);
printf("%ld\n",n);
NONO ( );
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *fp, *wf ;
int i ;
char s[20] ;
long n ;
fp = fopen("in.dat","r") ;
wf = fopen("out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(fp, "%s", s) ;
n = fun(s);
fprintf(wf, "%ld\n", n) ;
}
fclose(fp) ;
fclose(wf) ;
}
编写函数fun,将一个数字字符串转换为一个整数,例如,输入字符串"-1234",则函数把他转换为整数值-1234
标签:文件 turn 转换 logs == blog int 关闭 str
原文地址:http://www.cnblogs.com/jun699701/p/7531511.html