Tag: char

从C中的char *中获取单个字符

有没有办法逐个字符遍历或从C中的char *中提取单个字符? 请考虑以下代码。 现在哪个是获得个性化角色的最佳方式? 建议我不使用任何字符串函数的方法。 char *a = “STRING”;

为什么这个循环在c中运行无限次?

我只是在C编程中试验代码。 并且开始了解一种奇怪的行为。 嗯…因为我不是C的专家,所以我不知道它是奇怪的还是正常的。 基本上我的问题是关于以下两行代码之间的区别: – char a = ‘h’; // here variable a is not an array of “char” 和 char a = ‘hi’; //here variable a is not an array of “char” as well (i don’t know if compiler assumes it as an array or not but , at least i didn’t declared it […]

为什么结构中只有“char”类型的成员没有填充?

我在结构中只声明了char类型的成员。 #include struct st { char c1; char c2; char c3; char c4; char c5; }; int main() { struct st s; printf(“%zu\n”, sizeof(s)); return 0; } 输出: [ 现场演示 ] 5 那么,为什么结构中只有char类型成员没有填充?

在C中,如何删除char数组中相同且连续的行?

我正在寻找一些创建函数的帮助。 函数deleteIdents()将删除char数组中的相同行,因为它们是连续的。 它将保持相同的一条线。 我不需要检查整行是否相同。 只有前79个字符,MAXCHARS,适用于这种情况。 因此,例如,如果我的数组包含 Hello World Hi World Hello World Hello World Hello World Hi there 它将被改为 Hello World Hi World Hello World Hi there 在我的脑海中,该function看起来类似于: int deleteIdents(char *a) { int i; for (i=0; i<=MAXCHARS; i++) { if (a[i] != '\n') /* copy into new array */ } } } 但我不确定。 如果你有一个解决方案,我会很高兴和感谢听到它:)

char **应付字符串?

当我遇到char **时,我很困惑,是否真的有必要应对字符串? 例如: double strtod(const char *nptr,char **endptr); 如果endptr不为NULL,则指向停止扫描的字符的指针将存储在endptr指向的位置。 — MSDN 这很复杂,为什么不只是将指向字符的指针复制到endptr ? 调用之后的所有计算都可以通过将指针的值传递给endptr来实现。 真的需要char**吗?

错误:无效操作数到二进制+ char *

可能重复: C字符串连接 有以下代码: char *doencode(const unsigned char *input, int length) { //irrelevant code } char *fname, *lname; char *encoded, *name; name = fname + “|” + lname; encoded = doencode(name, 30); 我得到这个错误:二进制+的无效操作数 如何组合fname和| &lname?

编译器不会在scanf()上停止输入

这是一个小C代码 #include int main() { char ch=’Y’; while(ch==’Y’) { printf(“\nEnter new value for Y “); scanf(“%c”,&ch); if(ch==’Y’ || ch==’y’) // do some work printf(“Y was selected\n”); } printf(“exiting main”); return 0; } 我第一次输入’Y’作为输入(没有qoutes),循环返回true并第二次进入内部,但这次它没有在scanf()上停止用户输入。(请执行输入为为了清晰起见,’Y’。 输出如下所示: 如此处所示,编译器第二次没有停止输入。 这背后的原因是什么? 提前致谢 !

尖括号为Const Char

以下代码指向只读内存中可用的char数组中的第一个字符 。 是对的吗?: const char * ptr = “String one”; 现在当ptr开始指向另一个内存位置时: ptr = “String two”; 第一个char数组会发生什么? 执行结束时是否释放了该内存位置?

使用cython将double转换为char *

在Cython中,如何在不使用Python对象(例如bytes或str )作为中间体的情况下转换生成C double的C字符串( char * )表示? 事实上,我已经在C扩展名文件(.pyx)中定义了我的函数,如下所示: cdef void function(self, char* var1) nogil: cdef char* chaine =”” cdef double inter = 0.0 #Here there is some treatment which modifies the value of the local variable ‘inter’ so that it contains a double value different from 0 strcat(chaine , “(“) strcat(chaine , inter) strcat(chaine , “)**beta”) […]

C中未初始化数组中char的默认值是多少?

鉴于以下声明: char inputBuffer[12]; 数组中任何一个char的默认值是多少? 我很想知道这一点,因为如果我想在arrays中清除一个位置,我需要知道给它的价值。