Commit 4f46286b authored by Jingya Wu's avatar Jingya Wu
parents ccbfc9b8 640853ca
......@@ -24,7 +24,7 @@ CC = gcc
CFLAGS = -g -Wall
EXE = hexdump.o file_stat read_dir fdump traverse
EXE = sender receiver hexdump.o file_stat read_dir fdump traverse
all: $(EXE)
......@@ -55,5 +55,11 @@ traverse: traverse.o
traverse.o: traverse.c
$(CC) -c $(CFLAGS) traverse.c -o traverse.o
sender: sender.c
$(CC) $(CFLAGS) sender.c -o sender
receiver: receiver.c
$(CC) $(CFLAGS) receiver.c -o receiver
clean:
/bin/rm -f *~ *.o core $(EXE)
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char* argv[]){
FILE *file;
char* line;
char string[150];
while(1){
int count = 0;
file = fopen("channel.txt","r");
fseek(file, 0, SEEK_END);
long file_size = ftell(file);
fseek(file,0,SEEK_SET);
char *split = malloc(file_size+1);
fread(split, file_size,1,file);
split[file_size]=0;
line = strtok(split,"\n");
while(line != NULL) {
strcpy(string,line);
printf("%s\n",string);
line = strtok(NULL,"\n");
count++;
}
// printf("%s\n",string);
fclose(file);
free(split);
sleep(1);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#define SEM "Zara"
int main(int argc, char* argv[]){
FILE *file;
char *newLine = "\n";
file = fopen("channel.txt","a+");
fwrite(argv[1],sizeof(char),strlen(argv[1]),file);
fwrite(newLine,sizeof(char),strlen(newLine),file);
fclose(file);
return 0;
}
Prob 1 - works
Prob 2 - works
Prob 3 - works
Prob 4 -
run the command like:
./sender hi
./sender my
./sender name
./sender is
etc.
then call ./receiver
......@@ -50,6 +50,7 @@ void process(char *root)
unsigned int fd;
int num_dir = 0;
struct stat file_info;
time_t least_mod = INT_MAX;
struct dirent *dp;
DIR *dirp;
......@@ -57,7 +58,8 @@ void process(char *root)
initq(&nameq);
enqueue(root,&nameq);
time_t latest = 0;
char dName[MAXLENGTH];
char newest[MAXLENGTH] = "traverse.c";
char oldest[MAXLENGTH];
struct stat dStat;
while (true != queue_empty(nameq)) {
peek_front(dname,nameq);
......@@ -84,9 +86,13 @@ void process(char *root)
enqueue(cname,&nameq);
}
if (dStat.st_mtime > latest) {
strcpy(dName, dp->d_name);
strcpy(newest, dp->d_name);
latest = file_info.st_mtime;
}
if (dStat.st_mtime < least_mod) {
strcpy(oldest, dp->d_name);
least_mod = file_info.st_mtime;
}
}
closedir (dirp);
} else {
......@@ -118,8 +124,8 @@ void process(char *root)
printf(" the max file size is %d bytes\n",(int)max);
printf(" the min file size is %d bytes\n",(int)min);
printf(" the average file size is %f bytes\n",avg);
printf(" the file size that was most recently modified: %s\n",dName);
printf(" the file that was least recently modified is %f\n",avg);
printf(" the file size that was most recently modified: %s\n", newest);
printf(" the file that was least recently modified is: %s\n",oldest);
}
// initialize queue data structure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment