(New page: = ECE 264 Exam 3 Open Book<br> = <br>Read Write fopen<br>Text fgetc fprintf "r", "w"<br>fgets fputc "rb", "wb" binary fread size_t fread(void *p, size_t size, size_tn, FILE * f);<br>siz...)
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= ECE 264 Exam 3 Open Book<br> =
+
[[Category:ECE264]] [[Category:Programming]] [[Category:C]]
 +
=[[ECE264|ECE 264]]: Exam 3 Review (Open Book=
  
<br>Read Write fopen<br>Text fgetc fprintf "r", "w"<br>fgets fputc "rb", "wb"
+
<br>Read Write fopen<br>Text fgetc fprintf "r", "w"<br>fgets fputc "rb", "wb"  
  
binary fread
+
<br>
  
size_t fread(void *p, size_t size, size_tn, FILE * f);<br>size_t fwrite(
+
binary fread  
  
int count = fread(&amp;w, sizeof(int), 1, f);<br>count += fread(&amp;h,...,1,f)
+
size_t fread(void *p, size_t size, size_tn, FILE * f);<br>size_t fwrite(  
  
if(count ==2)<br>{
+
int count = fread(&amp;w, sizeof(int), 1, f);<br>count += fread(&amp;h,...,1,f)
  
<br>::void fclose(FILE *f)
+
if(count ==2)<br>{
  
::int feof(FILE *f)
+
<br>void fclose(FILE *f)  
  
dynamic structures?
+
int feof(FILE *f)
  
struct Blokus<br>{<br>:int clirn,<br>:char* data;
+
dynamic structures?
  
}
+
struct Blokus<br>{<br>int clirn,<br>char* data;
  
typedef struct IntValue {<br>:int value;<br>:struct IntValue *next;<br>} IntValue;
+
}  
  
IntValue *IntValue_create(int value)<br>{<br>:IntValue *iv = malloc(sizeof(IntValue));<br>:iv-&gt;value = value;<br>:iv-&gt;next = NULL;<br>:return iv;<br>}
+
typedef struct IntValue {<br>int value;<br>struct IntValue *next;<br>} IntValue;  
  
void IntValue_destroy(IntValue *iv)<br>{<br>:free(iv);<br>}
+
IntValue *IntValue_create(int value)<br>{<br>&nbsp; IntValue *iv = malloc(sizeof(IntValue));<br>&nbsp; iv-&gt;value = value;<br>&nbsp; iv-&gt;next = NULL;<br>&nbsp; return iv;<br>}  
  
IntValue *IntValueL_insertFront(IntValue *head, IntValue *node)<br>{<br>:node-&gt;next = head;<br>:return node;<br>}
+
void IntValue_destroy(IntValue *iv)<br>{<br>&nbsp; free(iv);<br>}  
  
void IntValueL_print(IntValue *head)<br>{<br>:whle (head!= NULL) {<br>:printf(" %d", head-&gt;value);<br>:head = head-&gt;next;<br>}<br>printf("\n");<br>}
+
IntValue *IntValueL_insertFront(IntValue *head, IntValue *node)<br>{<br>&nbsp; node-&gt;next = head;<br>&nbsp; return node;<br>}  
  
int IntValueL_getCount(IntValue *head)<br>{<br>:int count = 0;<br>:while (head !=NULL){<br>:count++;<br>;head = head-&gt;next;<br>}<br>:return count;<br>}<br>//put at back of list<br>IntValue *IntValueL_insertBack(IntValue *head, IntValue *node)<br>{<br>:if(head ==NULL) {<br>::node-&gt; next = NULL;<br>::return node;<br>}<br>:IntValue *curr = head;<br>:while (curr -&gt;next != NULL)<br>:{<br>::curr = curr-&gt;next;<br>:}<br>:curr-&gt;next = node;<br>:node -&gt; next = NULL;
+
void IntValueL_print(IntValue *head)<br>{<br>&nbsp; whle (head!= NULL) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp;%d", head-&gt;value);<br>&nbsp;&nbsp;&nbsp;&nbsp; head = head-&gt;next;<br>&nbsp; }<br>&nbsp; printf("\n");<br>}
  
<br>:}
+
int IntValueL_getCount(IntValue *head)<br>{<br>&nbsp; int count = 0;<br>&nbsp; while (head&nbsp;!=NULL){<br>&nbsp;&nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp;&nbsp; head = head-&gt;next;<br>&nbsp; }<br>&nbsp; return count;<br>}<br>//put at back of list<br>IntValue *IntValueL_insertBack(IntValue *head, IntValue *node)<br>{<br>if(head ==NULL) {<br>node-&gt; next = NULL;<br>return node;<br>}<br>IntValue *curr = head;<br>while (curr -&gt;next&nbsp;!= NULL)<br>{<br>curr = curr-&gt;next;<br>}<br>curr-&gt;next = node;<br>node -&gt; next = NULL;
  
<br>Reverse algorithm!<br>
+
<br>}<br>Reverse
  
:IntValue *new_head = NULL;<br>:while(head !=NULL){<br>::IntValue *tmp = head;<br>::head = head-&gt;next;<br>::new_head = IntValueL_insertFront(new_head,tmp);<br>:}<br>:return new_head;<br>}
+
IntValue *new_head = NULL;<br>&nbsp; while(head&nbsp;!=NULL){<br>&nbsp;&nbsp; IntValue *tmp = head;<br>&nbsp;&nbsp; head = head-&gt;next;<br>&nbsp;&nbsp; new_head = IntValueL_insertFront(new_head,tmp);<br>&nbsp; }<br>&nbsp; return new_head;<br>}<br>Find and delete?<br>int IntValueL_find(IntValue *head, int value)<br>{<br>//look for integery with value == to parameter being passed in<br>&nbsp; while( head!=NULL)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; if(head -&gt; value ==value) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return head;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; head = head-&gt; next;<br>&nbsp; }<br>&nbsp; return NULL;<br>}  
  
<br>Find and delete?<br>int IntValueL_find(IntValue *head, int value)<br>{<br>//look for integery with value == to parameter being passed in<br>:while( head!=NULL)<br>:{<br>::if(head -&gt; value ==value) {<br>:::return head;<br>::}<br>::head = head-&gt; next;<br>:}<br>:return NULL;<br>}
+
void IntValueL_delete
  
void IntValueL_delete
+
Master Struct<br>struct IntList
  
Master Struct<br>struct IntList
+
int main(int argc, char **argv)<br>{<br>&nbsp;&nbsp; IntValue *head=NuLL;<br>&nbsp;&nbsp; head = IntValueL_insertFront(head, IntValue_create(42));<br>&nbsp;&nbsp; head = IntValueL_insertFront(head, IntValue_create(64));<br>&nbsp;&nbsp; head = IntValueL_insertFront(head, IntValue_create(128));<br>&nbsp;&nbsp; head = IntValueL_insertFront(head, IntValue_create(11));<br>&nbsp;&nbsp; //looking for and find and print<br>&nbsp;&nbsp; printf("Value&nbsp;%d is at point&nbsp;%p\n"<br>}<br>  
  
int main(int argc, char **argv)<br>{<br>IntValue *head=NuLL;<br>head = IntValueL_insertFront(head, IntValue_create(42));<br>head = IntValueL_insertFront(head, IntValue_create(64));<br>head = IntValueL_insertFront(head, IntValue_create(128));<br>head = IntValueL_insertFront(head, IntValue_create(11));<br>//looking for and find and print<br>printf("Value %d is at point %p\n"<br>}<br><br>
+
<br><br>
 +
----
 +
[[2011_Spring_ECE_264_Lu|Back to ECE264, Spring 2011, Prof. Lu]]

Latest revision as of 05:32, 11 July 2012

ECE 264: Exam 3 Review (Open Book)


Read Write fopen
Text fgetc fprintf "r", "w"
fgets fputc "rb", "wb"


binary fread

size_t fread(void *p, size_t size, size_tn, FILE * f);
size_t fwrite(

int count = fread(&w, sizeof(int), 1, f);
count += fread(&h,...,1,f)

if(count ==2)
{


void fclose(FILE *f)

int feof(FILE *f)

dynamic structures?

struct Blokus
{
int clirn,
char* data;

}

typedef struct IntValue {
int value;
struct IntValue *next;
} IntValue;

IntValue *IntValue_create(int value)
{
  IntValue *iv = malloc(sizeof(IntValue));
  iv->value = value;
  iv->next = NULL;
  return iv;
}

void IntValue_destroy(IntValue *iv)
{
  free(iv);
}

IntValue *IntValueL_insertFront(IntValue *head, IntValue *node)
{
  node->next = head;
  return node;
}

void IntValueL_print(IntValue *head)
{
  whle (head!= NULL) {
      printf(" %d", head->value);
     head = head->next;
  }
  printf("\n");
}

int IntValueL_getCount(IntValue *head)
{
  int count = 0;
  while (head !=NULL){
     count++;
     head = head->next;
  }
  return count;
}
//put at back of list
IntValue *IntValueL_insertBack(IntValue *head, IntValue *node)
{
if(head ==NULL) {
node-> next = NULL;
return node;
}
IntValue *curr = head;
while (curr ->next != NULL)
{
curr = curr->next;
}
curr->next = node;
node -> next = NULL;


}
Reverse

IntValue *new_head = NULL;
  while(head !=NULL){
   IntValue *tmp = head;
   head = head->next;
   new_head = IntValueL_insertFront(new_head,tmp);
  }
  return new_head;
}
Find and delete?
int IntValueL_find(IntValue *head, int value)
{
//look for integery with value == to parameter being passed in
  while( head!=NULL)
  {
     if(head -> value ==value) {
      return head;
    }
    head = head-> next;
  }
  return NULL;
}

void IntValueL_delete

Master Struct
struct IntList

int main(int argc, char **argv)
{
   IntValue *head=NuLL;
   head = IntValueL_insertFront(head, IntValue_create(42));
   head = IntValueL_insertFront(head, IntValue_create(64));
   head = IntValueL_insertFront(head, IntValue_create(128));
   head = IntValueL_insertFront(head, IntValue_create(11));
   //looking for and find and print
   printf("Value %d is at point %p\n"
}




Back to ECE264, Spring 2011, Prof. Lu

Alumni Liaison

Followed her dream after having raised her family.

Ruth Enoch, PhD Mathematics