[Segmentation Fault] Oops! The filename points to a constant string
2013-02-24 15:49
411 查看
We can compile the following program using the gcc compiler.
But when running it, we get a segmentation fault.
Why ?
But when running it, we get a segmentation fault.
Why ?
#include <stdio.h> int main() { // The following statement is equal to " constant char* filename = "file1.txt"; "in c++ char* filename = "file1.txt"; // Initialization and after that filename points to a constant string. printf("\nPlease input for the filename ==> "); scanf("%s", filename); // Try to modify a constant string. It will cause a segmentation fault ! printf("\nThe file name you have input is %s", filename); return 0; }
相关文章推荐
- string - How to get the filename without the extension from a path in Python? - Stack Overflow
- Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
- 【获取、高亮UIWebView中选择的文本】How To Mark Or Get The Highlighted String Inside UIWebView
- 将字符串转换为整数 Convert the string to integer
- deprecated conversion from string constant to 'char *' 解决方案
- "String Concatenation vs String Builder - The performance hit! See it to believe it :o)"
- warning: deprecated conversion from string constant to 'char*'
- The constructor ClassPathXmlApplicationContext(String) refers to the missing type
- warning:deprecated conversion from string constant to 'char *'解决方案
- warning:deprecated conversion from string constant to 'char *'解决方案
- warning: deprecated conversion from string constant to ‘char的解决方法
- warning:deprecated conversion from string constant to 'char *'解决方案
- JSP页面中的request.getContextPath()出现“ .... .. refers to the missing type String”错误
- 解决“invalid conversion from void* to char*”和“deprecated conversion from string constant to 'char*' "
- The method decodeBuffer(String) from the type CharacterDecoder is not accessible due to restriction
- deprecated conversion from string constant to 'char*' 解决方法
- [ndk]Android NDK: Your APP_BUILD_SCRIPT points to an unknown file/Please define the NDK_PROJECT_PATH
- 指针数组与const指针,以及warning:deprecated conversion from string constant to 'char *'
- warning: deprecated conversion from string constant to "char *"
- 解决C++中[Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]