#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"fcntl.h"
#define X 7
#define Y 128
#define FILE_OPEN_FAILED -1
#define SUCESS 1
int CopyData_From_Txt(char* from_file,int arr[][Y])
{
int fd,read_size;
int i,j,k=0;
int MAX_SIZE=896;
char* fbuff=(char*)malloc(MAX_SIZE);
char* buff=fbuff;
fd=open(from_file,O_RDWR,0777);
if(fd==-1)
{
printf("The file of %s don't exist\n",from_file);
return FILE_OPEN_FAILED;
}
while(read_size=read(fd,buff,MAX_SIZE)>0)
printf("%s\n",buff);
while(*buff++)
{
if(*buff==','){
*buff=' ';
}
k++;
}
printf("%s\n",fbuff);
lseek(fd,0,SEEK_SET);
int n=write(fd,fbuff,k);
free(fbuff);
fbuff=NULL;
buff=NULL;
close(fd);
return SUCESS;
}
int main(int argc,char* argv[])
{
//char* filename="./mouse10.txt";
int arr[X][Y];
if(argc==1)
{
printf("please input like this:\n ./a.out filename\n");
return -1;
}
CopyData_From_Txt(argv[1],arr);
return 0;
}
~
转载请注明原文地址: https://ju.6miu.com/read-900187.html