Line 77: Line 77:
 
   dst->label = 1;
 
   dst->label = 1;
 
    
 
    
 +
}
 +
 +
==================================================
 +
April 19th, Wudi Zhou, Prof. Lu's section
 +
 +
Q1:
 +
 +
textfile = fopen(argc[1],"r");
 +
while(fscanf(textfile,"%d",&temp) != EOF)
 +
{
 +
sum = sum + temp;
 +
}
 +
binarayfile = fopen(argv[2],"rb");
 +
while(fread(&temp,sizeof(int),1,binaryfile) != 0)
 +
{
 +
sum = sum + temp;
 +
}
 +
 +
output = fopen(argv[3],"w");
 +
fpeintf(output,"%d\n",sum);
 +
 +
Q2:
 +
 +
Thing Thing_construct(int w, char * l)
 +
{
 +
Thing thing;
 +
thing.label = malloc(sizeof(char) * strlen(l) + 1));
 +
thing.weight = w;
 +
strcpy(thing.label,l);
 +
return thing;
 +
}
 +
 +
Thing Thing_copy(Thing p)
 +
{
 +
Thing copy;
 +
copy = Thing_construct(p.weight,p.label);
 +
return copy;
 +
}
 +
 +
void Thing_merge(THing *dst, Thing src)
 +
{
 +
dsr -> weight = dst-> weight + src.weight;
 +
char * p = dst->label;
 +
dst->label = malloc(sizeof(char) * (strlen(dst->label) + 1 + strlen(src.label));
 +
strcpy(dst->label,p);
 +
free(p);
 +
dst -> label = srecat(dst -> label,src.label);
 +
 +
return;
 
}
 
}

Revision as of 20:27, 18 April 2012

Shiyu Wang Lec25 April 14th

Exam average is around 5-6

for text file

fscanf(filename,"%d",&val)

for binary file

fread(&val, sizeof(int), 1, filename)

===================

Kevin Tan(0023987592), section#2 notes 04/12

EXAM Q2 Thing thing_construct(int w,char *l) {

 Thing t;
 t.label = strdup(1);
 t.weight = w;
 return t;
 

}

Thing Thing_copy(Thing p) {

 return thing_construct(P.weight,P.label)

}

void Thing_merge(Thing *dst,Thing src) {

 char *l;
 dst->weight = src.weight;
 char *l1 = dst->label;
 char *l2= src.label;
 l= malloc(sizeof(char)*(strlen(l1)+strlen(l2)+1));
 strcpy(l,l1);
 strcpy(l,l2);
 free(dat->label);
 dst->label = 1;
 

}

void Thing_destory(Thing p) {

 free(p.label);

}

void Thing_print(Thing p) {

 printf("weight = %d, label = %s\n",p.weight,p.label);

}

==========================

Hanye Xu April 17

For exam2

fscanf(filename,"%d",&val) fread(&val, sizeof(int), 1, filename)

for the first Question

For the Q2:

void Thing_merge(Thing *dst,Thing src) {

 char *l;
 dst->weight = src.weight;
 char *l1 = dst->label;
 char *l2= src.label;
 l= malloc(sizeof(char)*(strlen(l1)+strlen(l2)+1));
 strcpy(l,l1);
 strcpy(l,l2);
 free(dat->label);
 dst->label = 1;
 

}

======================================

April 19th, Wudi Zhou, Prof. Lu's section

Q1:

textfile = fopen(argc[1],"r"); while(fscanf(textfile,"%d",&temp) != EOF) { sum = sum + temp; } binarayfile = fopen(argv[2],"rb"); while(fread(&temp,sizeof(int),1,binaryfile) != 0) { sum = sum + temp; }

output = fopen(argv[3],"w"); fpeintf(output,"%d\n",sum);

Q2:

Thing Thing_construct(int w, char * l) { Thing thing; thing.label = malloc(sizeof(char) * strlen(l) + 1)); thing.weight = w; strcpy(thing.label,l); return thing; }

Thing Thing_copy(Thing p) { Thing copy; copy = Thing_construct(p.weight,p.label); return copy; }

void Thing_merge(THing *dst, Thing src) { dsr -> weight = dst-> weight + src.weight; char * p = dst->label; dst->label = malloc(sizeof(char) * (strlen(dst->label) + 1 + strlen(src.label)); strcpy(dst->label,p); free(p); dst -> label = srecat(dst -> label,src.label);

return; }

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett