|
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
main ()
{
char name[8];
char buf[1024];
int a,b;
printf ("input content:");
gets (buf);
printf ("input file name:");
scanf ("%s", name);
a = open (name, O_WRONLY);
write (a, buf,strlen(buf));
close (a);
}
a very funny thing:in the codes above,if i put scanf before gets(),just like:
.............
printf ("input file name:");
scanf ("%s", name);
printf ("input content:");
gets (buf);
............
after i compile it,the program will be quit automatically
who can tell me why?
sorry,there are some bugs with my xsim,so i had to type all in Eng |
|