Skip to content

Instantly share code, notes, and snippets.

@ahmedengu
Last active April 13, 2016 09:48
Show Gist options
  • Save ahmedengu/46be4c9343b6523e64968292a4ae1133 to your computer and use it in GitHub Desktop.
Save ahmedengu/46be4c9343b6523e64968292a4ae1133 to your computer and use it in GitHub Desktop.
read text and convert it to uppercase
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <ctype.h>
char inputString[100],uppercaseString[100];
sem_t len;
void *reader() {
printf("Enter first text:");
scanf("%s", inputString);
printf("\n %s", inputString);
sem_post(&len);
}
void *writer() {
sem_wait(&len);
for (int i = 0; i<100; i++) {
uppercaseString[i]=toupper(inputString[i]);
}
printf("\nUpper: %s", uppercaseString);
}
int main() {
pthread_t tid1,tid2;
pthread_create(&tid1, NULL, reader, NULL);
pthread_create(&tid2, NULL, writer, NULL);
pthread_join(tid1, NULL);
pthread_join(tid1, NULL);
return 0;
}
Enter first text:
5eukuei
Upper 5EUKUEI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment