C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > C on Unix sample source codes
String manipulation using message Queue
String manipulation using message Queue Queue.h ------- #include
#include
#include
#include
struct queue { long type; char msg[50]; }; Queue.c ------- #include "queue.h" int main() { struct queue q; int mid; if((mid=msgget(ftok("string",0x99),0644|IPC_CREAT))<0) { if(mid!=-1) { printf("Message Queue Error "); exit(1); } else { printf("Message Already Exist "); exit(1); } } printf(" Enter the Message Type:"); scanf("%d",&q.type); while(q.type>0) { printf(" Enter the Message:"); getchar(); gets(q.msg); if(msgsnd(mid,&q,sizeof(q),IPC_NOWAIT)<0) { printf("Message send Error "); exit(1); } printf(" Enter the Message Type:"); scanf("%d",&q.type); } return 0; } Word.c ------ #include "queue.h" #include
void word(char* str) { int i,n,w=1; n=strlen(str); for(i=0;i
void rev(char* str) { char s[30]; int i,j,n; n=strlen(str); printf("Reverse for "%s" :",str); for(i=n;i>=0;i--) putchar(str[i]); printf(" "); } int main() { struct queue q; int mid; long type; if((mid=msgget(ftok("string",0x99),0644 ))<0) { printf("Message Queue Error "); exit(1); } printf(" Enter the Message Type to Reterive:"); scanf("%d",&type); while(msgrcv(mid,&q,sizeof(q),type,IPC_NOWAIT) && errno!=ENOMSG) { rev(q.msg); } }
Privacy Policy
|
Link to Us
|
Links