c-strings

    12热度

    4回答

    我不是C程序员,所以我不熟悉C字符串,但是我必须使用C库,因此这里缩短了我的代码版本来证明我的问题: char** ReadLineImpl::my_completion() { char* matches[1]; matches[0] = "add"; return matches; } 我得到一个警告: 警告 - 与局部变量相关的堆栈存储器的地址“

    -1热度

    1回答

    我正在开发一个使用unordered_map和char *在C++中的命令行程序。 但是,它不起作用。 这是我的代码。 #include "stdafx.h" #include <unordered_map> int main(int argc, char *argv[]) { std::unordered_map <char*, char*> hash; for (

    0热度

    2回答

    我对C很陌生,实现了一个将稀疏矩阵写入文件的函数。 我想知道什么是正确的方式是在我写入文件之前在C中建立一个字符串。 我目前打电话给write()很多,导致表现不佳。我必须格式化字符串并在循环内顺序构建它。在Java中,我会使用StringBuilder,但我不知道C等价物。 这里是我想做的事 int i; unsigned int u; for(i=0 ; someCondition ; i

    2热度

    2回答

    我有这样的代码: char* env; if (getenv("MP") == NULL) { env = "/usr"; } else { env = getenv("MP"); } printf("($MP is %s)\n", env); printf("The program seg faults without printing me :(");

    1热度

    3回答

    我可以这样吗? #include <stdio.h> #define CAT2(a1, a2) #a1 ## ";" ## #a2 int main(void) { const char *ch1 = "1"; const char *ch2 = "2"; puts(CAT2(ch1, ch2)); } 输出: 1; 2 但是目前我有 CH1; CH

    -3热度

    1回答

    帮助我解决这个问题。我在ubuntu12.04上使用GCC。当我编写这个程序从键盘n获得5个字符串时,然后在屏幕上打印这些字符串。程序被编译,但在执行期间,它从键盘获取字符串,但只打印最后一个字符串我所编写的程序是如下: void main() { char names[10]; int i,j; for(i=0;i<5;i++) { pr

    0热度

    3回答

    该程序为什么会引发分段错误?这些函数单独运行,但我不明白为什么当我尝试将字符串存储在数组中时出现错误。我需要将所有可能的回文存储在数组中。 #include <stdio.h> #include <string.h> #include <stdlib.h> int isPal(char s[]) { int i = 0, j = 0; while(s[j]) {

    0热度

    1回答

    在我们的项目中,我们有数百个标识符用于错误代码,例如: #define SYS_FAIL_EXCEP_PREFETCH_ABORT 0 #define SYS_FAIL_EXCEP_DATA_ABORT 1 #define SYS_FAIL_EXCEP_RESET 2 #define SYS_FAIL_EXCEP_UNDEFINED 3 #define SYS_FAIL_EXCEP

    2热度

    3回答

    char Str[][5]={"one","two","three","four","five"}; char Str1[][6]={"one","two","three","four","five","six"}; printf("Size of Str is %d",sizeof(Str)); printf("\nSize of Str1 is %d",sizeof(Str1));

    -2热度

    3回答

    是不是说编译器自动添加了终止C字符串的null是正确的? 因此,在下面的例子: char * str = "0124"; printf("%x", str[str[3] - str[2] + str[4]]); 输出总是32? 谢谢。