user-0 提问: 请教sprintf的用法，为什么这段程序会运行崩溃

回复:
user: user-1
content: 引用 10 楼 newerC 的回复:char c[] 极端情况需要能表示"255.255.255.255"这种IP地址，字符长度共 3+1+3+1+3+1+3 = 15 所以c至少需要申明为char c[15+1]正解！！！

user: user-2
content: 看懂返回值 Return value “Upon successful return, these functions return the number of characters printed (not including the trailing '\0' used to end output to strings).”

user: user-3
content: 数组越界

user: user-4
content: char c[] 极端情况需要能表示"255.255.255.255"这种IP地址，字符长度共 3+1+3+1+3+1+3 = 15 所以c至少需要申明为char c[15+1]

user: user-5
content: sprintf第一个参数是字符串类型的好不好，你那里整型肯定不行，自己百度一下sprintf的用法

user: user-6
content: 引用 7 楼 a1232345 的回复:[quote=引用 4 楼 u014749886 的回复:] char c[8]  不够用啊，最起码也得  至少也得16吧 请问这个16是怎么看出来的，大小是看最后形成的字符串大小吗？，4个%u = 16，但不是还有几个点吗，应该是20 吧？[/quote] 有那个时间掰指头计算长度，还不一定计算正确，为什么不略微多定义几个字符保证其够用呢？

user: user-0
content: 引用 4 楼 u014749886 的回复:char c[8]  不够用啊，最起码也得  至少也得16吧 请问这个16是怎么看出来的，大小是看最后形成的字符串大小吗？，4个%u = 16，但不是还有几个点吗，应该是20 吧？

user: user-6
content: 搜“编译器 堆栈检查”

user: user-0
content: 引用 4 楼 u014749886 的回复:char c[8]  不够用啊，最起码也得  至少也得16吧 为什么我改成char c[20](4个int+4个'.')，编译运行可以了。但是gcc的时候加上-g就报错了了？

user: user-1
content: char c[8]  不够用啊，最起码也得  至少也得16吧

user: user-7
content: 栈溢出了，试给程序多分配一些栈空间。

user: user-6
content: PRINTF Section: Linux Programmer's Manual (3 ) Updated: 2000-10-16  --------------------------------------------------------------------------------    NAME printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - formatted output conversion    SYNOPSIS #include <stdio.h>  int printf(const char *format, ...);  int fprintf(FILE *stream, const char *format, ...);  int sprintf(char *str, const char *format, ...);  int snprintf(char *str, size_t size, const char *format, ...);   #include <stdarg.h>   int vprintf(const char *format, va_list ap);  int vfprintf(FILE *stream, const char *format, va_list ap);  int vsprintf(char *str, const char *format, va_list ap);  int vsnprintf(char *str, size_t size, const char *format, va_list ap);     DESCRIPTION The functions in the printf family produce output according to a format as described below. The functions printf and vprintf write output to stdout, the standard output stream; fprintf and vfprintf write output to the given output stream; sprintf, snprintf, vsprintf and vsnprintf write to the character string str.  The functions vprintf, vfprintf, vsprintf, vsnprintf are equivalent to the functions printf, fprintf, sprintf, snprintf, respectively, except that they are called with a va_list instead of a variable number of arguments. These functions do not call the va_end macro. Consequently, the value of ap is undefined after the call. The application should call va_end(ap) itself afterwards.   These eight functions write the output under the control of a format string that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities of stdarg(3)) are converted for output.     Return value Upon successful return, these functions return the number of characters printed (not including the trailing '\0' used to end output to strings). The functions snprintf and vsnprintf do not write more than size bytes (including the trailing '\0'). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing '\0') which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. (See also below under NOTES.) If an output error is encountered, a negative value is returned.

user: user-6
content: 进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈，内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件，参考“ulimit -c core文件最大块大小”命令