scanf strange behavior
hello:
Here is the program I try to send queue,I try to read some imformaiton from stdin and load it in structure and then send to queue, but the scanf don't wait for me to input value
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
extern int errno;
int main()
{
struct msgbuf1{
long mtype;
char mtext[100];
} sndbuf , *msgp;
int rtrn, msgqid ;
char strbuf[100];
if ( (msgqid = msgget(0x888, IPC_CREAT|0600)) == -1 )
{fprintf(stderr, "msgget 888 failed !\n");exit(1);}
while(1)
{
msgp=&sndbuf;
printf("請輸入交易種類\n");
scanf(strbuf);
msgp->mtype=atoi(strbuf);
printf("請輸入帳戶姓名\n");
scanf("%s",sndbuf.mtext);
strcat(sndbuf.mtext,"|");
printf("請輸入帳戶餘額\n");
scanf(strbuf);
strcat(sndbuf.mtext,strbuf);
rtrn=msgsnd(msgqid,msgp,strlen(sndbuf.mtext),0);
if (rtrn == -1)
{perror("msgsnd");exit(2);}
}
}
|