Problem 1
Problem 1
Problem 1
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>
if(fork() == 0){
//Child process
while(num > 1){
printf("%d ", num);
if(num %2 == 0)
num = num / 2;
else
num = 3 * num + 1;
}
printf("1\n\n");
}
else{
//Parent process - waiting for child to complete
wait(NULL);
}
return 0;
}
Problem 2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXCHARS 80
struct FileInfo {
char *name; /* name of file */
int numLines; /* number of lines in file */
int numWords; /* number of words in file */
int numChars; /* number of characters in file */
} fileInfo;
int countWords(char *);
int main(int argc, char **argv) {
FILE *fp;
struct FileInfo *info; /* array of counts for each file */
int numLines = 0, numWords = 0, numChars = 0; /* total counts */
char inString[MAXCHARS];
char *rs;
/* allocate array of structs containing counts for each file */
info = (struct FileInfo *) malloc((argc-1) * sizeof(struct FileInfo));
if (isalnum(inS[strlen(inS)-2]) || ispunct(inS[strlen(inS)-2])) {
numTokens++;
}
return numTokens;
}