CS604P - Assignment 01 - SOLUTION
CS604P - Assignment 01 - SOLUTION
All The Guidance You Need to Boost Your Studies: Handouts, Assignments, Quizzes, GDBs, Past Papers,
Projects.
This is Correct but Public Solution. For Unique & Authentic Solution, Please Contact ➔
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <ctype.h>
int sum = 0;
char name[100];
char modified[100];
// Thread T1: Read integers from input.txt, calculate sum, write to output.txt
void* thread1_func(void* arg) {
FILE* fp = fopen(INPUT_FILE, "r");
if (!fp) {
perror("Failed to open input.txt");
pthread_exit(NULL);
}
int num;
while (fscanf(fp, "%d", &num) == 1) {
sum += num;
}
fclose(fp);
strcpy(modified, name);
for (int i = 0; modified[i] != '\0'; i++) {
char ch = tolower(modified[i]);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
modified[i] = '*';
}
}
int main() {
// Check if input.txt exists, else create it
FILE* check = fopen(INPUT_FILE, "r");
if (!check) {
FILE* create = fopen(INPUT_FILE, "w");
if (!create) {
perror("Failed to create input.txt");
return 1;
}
fprintf(create, "10\n20\n30\n40\n50\n");
fclose(create);
} else {
fclose(check);
}
return 0;
}
Screenshot:
✔ Aapko 100% Correct, FREE, CLEAN, Authentic Solution Files milein gy.