#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main (void){
int fd,len,gd,i,j,p,q,x,y,temp,u,uname;
int l=0;
int z=0;
int t = 0;
char str[100];
char newstr[100];
char price[100];
char number[100];
char name[1024];
int a,b;
int c[5] = {0,11,22,36};
fd = open("a.txt", O_RDWR); //以读写方式打开
len = read(fd, str, 100); /* 读取文件内容 */
str[len] = '\0';
printf("%s\n", str);
gd = open("hello.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
for(temp = 0;temp<4;temp++){
//将单价赋值给price数组
for(i = c[temp];i<len;i++){
if(str[i] == ',') {
p = i;
break;
}
}
for(uname = c[temp];uname<p;uname++){
name[l] = str[uname];
l++;
}
for(u = p+1;u<len;u++){
if(str[u] == ',') {
q = u;
break;
}
}
for(j = p+1;j<q;j++){
price[z] = str[j];
z++;
}
//将数量赋值给number数组
x = q+1;
number[t] = str[x];
a = atoi(price);
b = atoi(number);
sprintf(newstr,"%s的总价格为:%d \n",name,a*b);
write(gd, newstr,strlen(newstr));
a=0;b=0;
memset(price,0, sizeof price);
z=0;
memset(name,0, sizeof name);
l=0;
}
close(gd);
}