问题标签 [character-arrays]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
38 浏览

c - 如何实现一个循环来读取检查大写字母数量等的名称数组?

程序原样告诉我有 0 个大写字母 0 个小写字母 0 个空格和 0 个制表符,但一个具有 2 个小写字母名称的数组还有 61 个其他字符。这些名称由 10 个字母组合而成。我想我需要一个循环来遍历数组,但我不确定这是否正确或我将如何做到这一点。

0 投票
1 回答
4165 浏览

c++ - 如何在 x86 程序集中增加数组?

您将如何在 for 循环中使用 x86 程序集递增数组。如果循环(使用 c++ 制作)看起来像:

将数组中的值放入寄存器中,然后将更改后的值放入单独的数组中。我将如何增加 x86 程序集中的每个数组(我知道 c++ 更简单,但它是练习工作),以便每次循环迭代使用的值并且放入数组中的值比上一次高一个?除了数组操作之外,循环中发生的事情的细节并不重要,因为我想知道一般情况下如何做到这一点,而不是具体情况?

0 投票
2 回答
17438 浏览

c - Doesn't %[] or %[^] specifier in scanf(),sscanf() or fscanf() store the input in null-terminated character array?

Here's what the Beez C guide (LINK) tells about the %[] format specifier:

It allows you to specify a set of characters to be stored away (likely in an array of chars). Conversion stops when a character that is not in the set is matched.

I would appreciate if you can clarify some basic questions that arise from this premise:

1) Are the input fetched by those two format specifiers stored in the arguments(of type char*) as a character array or a character array with a \0 terminating character (string)? If not a string, how to make it store as a string , in cases like the program below where we want to fetch a sequence of characters as a string and stop when a particular character (in the negated character set) is encountered?

2) My program seems to suggest that processing stops for the %[^|] specifier when the negated character | is encountered.But when it starts again for the next format specifier,does it start from the negated character where it had stopped earlier?In my program I intend to ignore the | hence I used %*c.But I tested and found that if I use %c and an additional argument of type char,then the character | is indeed stored in that argument.

3) And lastly but crucially for me,what is the difference between passing a character array for a %s format specifier in printf() and a string(NULL terminated character array)?In my other program titled character array vs string,I've passed a character array(not NULL terminated) for a %s format specifier in printf() and it gets printed just as a string would.What is the difference?

//Program to illustrate %[^] specifier

//character array vs string

Output JON

//Using %c instead of %*c

Output fruit,apple,lemon,and the character is |

0 投票
2 回答
28209 浏览

c - 为什么在字符串数组中添加空字符?

我知道我们必须使用空字符来终止这样的字符串数组:

但我只是想知道为什么必须使用空字符来终止这样的数组?

另外,我们为什么不添加一个空字符来终止这些:-

0 投票
1 回答
30 浏览

segmentation-fault - 字符数组分割错误

为什么这会产生分段错误?

输出:char 是 d 分段错误

为什么它在第二个字符串上出错?我只是想理解它...

0 投票
3 回答
177 浏览

c - C 字符串程序的输出

1.当我在 C (gcc-4.7.2) 中运行此程序时,由于缺少空字符 ('\0'),我预计会出现运行时错误。

2.如果程序仍然编译和执行成功,因为s[4]还没有被初始化,我预计那个地方会有一些垃圾值..但我也错了。

上述程序的输出是: abcde $$ 两个$(dollor) 之间没有字符,表示printf 跳过s[4]。这是相同的ideone链接:http: //ideone.com/UUQxb2

解释这种行为的原因(输出)?

0 投票
3 回答
13419 浏览

c - 在C中减去两个字符串

好吧,我实际上是在看 strcmp(),对它的工作感到困惑。无论如何我写了这段代码

我得到的输出为

谁能解释为什么会这样16

0 投票
2 回答
128 浏览

c - 如何创建一个接口来为 fortran 转换 ac 字符数组

我正在用 c 为 fortran 程序编写一个模块,我需要将一些字符串传递给 fortran 程序。我无法修改 fortran 代码,但可以编写自己的 fortran 代码来调用现有代码。我试过用谷歌搜索这个,有很多不同的方法写在我不理解的水平上。

c 字符串的长度是可变的(尽管它是在传递之前设置的)。fortran“字符串”被声明为字符*(*),所以我看不到字符数组需要填充的长度。这是一些代码片段,看看我需要做什么。

我正在编写的 c 函数:

我无法修改的 fortran 函数使用名称执行一些操作,然后为句柄设置一个值:

我认为最好的方法是创建一个单独的 c 函数,将 geom_name 解析为一些 fortran 将使用的内容,然后创建一个 fortran 函数来创建 fortran 字符串并将其传递给我无法更改的函数,但是我不知道该怎么做。有什么帮助吗?

0 投票
2 回答
806 浏览

c++ - c++ char数组大小验证

我有一个可以容纳 1000 个元素的字符数组('\0' 为 +1)。该数组将由用户输入填充。我想知道是否有任何方法可以检查输入是否超过数组可以容纳的数量。如果我尝试添加它,程序会在我比较它的大小之前崩溃。我正在考虑扩展数组并查看输入是否少于 1000 个字符,但这个想法对我来说似乎并不是一个很好的想法。

编辑:

std::cin.getline()用来从用户那里获取输入并且不能使用Sting该类

0 投票
2 回答
1216 浏览

c - C中的字符数组(Puts vs printf)

我对 C 中的字符数组有一些疑问,我有一个大小为 1 的字符数组,逻辑上说当我输入超过 2 个字符时,我应该遇到分段错误,但是puts正确打印出数组,而printf打印出某些部分数组连同垃圾值,为什么会这样

输出/输出:

除此之外,我必须在array size程序中输入多个字符以引发分段错误。是因为堆栈中的 SFP 吗?SFP的大小是4个字节如果我错了请纠正我