//: READSOURCE.C -- ReadSource file
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#define SZ 100
int main(void)
{
FILE *p;
FILE *np; // New file point
char *str; // temp string
int Rowjsq; // the count of the row
str=malloc(SZ * sizeof(char));
memset(str,'/0',sizeof(str));
p=fopen("readsource.c","r");
assert(p);
np=fopen("readsource.out","w");
assert(np);
Rowjsq=0;
while(fgets(str,SZ,p) !=NULL)
{
if(ferror(p))
{
printf( itoa(Rowjsq) + "read file failed!/n");
return -1;
}
printf("%s",str);
fputs(str,np);
if(ferror(np))
{
printf("write file failed!/n");
return -2;
}
Rowjsq++;
}
fclose(p);
fclose(np);
free(str);
return 0;
}
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#define SZ 100
int main(void)
{
FILE *p;
FILE *np; // New file point
char *str; // temp string
int Rowjsq; // the count of the row
str=malloc(SZ * sizeof(char));
memset(str,'/0',sizeof(str));
p=fopen("readsource.c","r");
assert(p);
np=fopen("readsource.out","w");
assert(np);
Rowjsq=0;
while(fgets(str,SZ,p) !=NULL)
{
if(ferror(p))
{
printf( itoa(Rowjsq) + "read file failed!/n");
return -1;
}
printf("%s",str);
fputs(str,np);
if(ferror(np))
{
printf("write file failed!/n");
return -2;
}
Rowjsq++;
}
fclose(p);
fclose(np);
free(str);
return 0;
}