- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将字符串修剪成 N 个字符的片段,然后将它们作为字符串数组传递到函数中?
这是我程序中转换二进制<->十六进制的部分。
我尝试用字符串做同样的事情,但没有成功。
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <String.h>
#define MAXDIGITS 8 // 8bits
int main()
{
int y;
printf("Binary-Hex convertor\n");
printf("Enter the Binary value : ");
scanf("%d", &y);
int i = MAXDIGITS - 1;
int array[MAXDIGITS];
while(y > 0)
{
array[i--] = y % 10;
y /= 10;
}
printf("%s", "-----------------\n");
printf("%s", "HEX:");
int x = array[0];
int x1 = array[1];
int x2 = array[2];
int x3 = array[3];
int x4 = array[4];
int x5 = array[5];
int x6 = array[6];
int x7 = array[7];
char buffer[50];
char buffer2[50];
char buffer3[50];
}
最佳答案
如果它只是从字符串的二进制到十六进制,那么这会容易得多......
char *input_string = "1001010101001010";
int count = 0;
int value = 0;
while ( *input_string != '\0' )
{
// Might be worth checking for only 0 and 1 in input string
value <<= 1;
value |= (int)((*input_string--) - '0');
if ( ++count == 8 || *input_string == '\0' )
{
// USE value to print etc, if you want to display use
// the following else you could store this in an array etc.
printf("%x ", value);
count = 0;
value = 0;
}
}
关于c - 如何修剪字符串数组并将其传递到函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7862642/
在字符串 (\test.something) 之后删除所有内容的命令是什么。 我在文本文件中有信息,但是在字符串之后有 1000 行我不想要的文本。如何删除包括字符串在内的所有内容。 这就是我所拥有的
我想删除每个项目的空白.amount 我在 .amount 类上使用 trim 和 each,但它似乎不起作用: jQuery('.amount').each(function(){ jQue
我列出了以下正在稳步增加的点,例如: [[0, 0], [9, 4], [18, 19], [25, 34], [48, 48], [54, 53], [61, 65], [69, 82], [73,
清理自动生成的 html 带来更多乐趣。标签中注入(inject)了大量无关的空格: Lorem Ipsum dolor sit... ( 代表实际空间,而不是实
计算 trimmed 的有效方法是什么?或winsorized列表的标准差? 我不介意使用numpy,但如果我必须制作列表的单独副本,它会非常慢。 最佳答案 这将制作两个副本,但您应该尝试一下,因为它
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicate: Leave only two decimal places after the dot Formatting
我正在使用绑定(bind)来填充 Listbox,其中包含 TextBlock 等。 问题是: 如何确保绑定(bind)到 TextBlock 的 Text 属性的文本具有特定长度,或者它是显示为某些
我正在按以下方式修剪 NSString: NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
我有一个文本列,其内容在字符串的前后混合了换行符和空白字符。我正在尝试编写一个 SELECT 语句,它向我显示没有前导和尾随垃圾的内容。 以下查询修剪空格: SELECT TRIM(column) F
这个问题在这里已经有了答案: How to slice a pandas DataFrame by position? (5 个答案) 关闭 5 年前。 我似乎看不出这里有什么问题。我有一个长度为
我没有找到类似的问题可能是因为我没有找到正确的词(英语不是我的母语) 问题 我有一个 varchar 值,末尾有一个空格:"opt-193-381-markets " 当我执行 SELECT 的值没有
假设我有 $url="../folder/file",我想找到并删除 ../ 部分。 我正在使用 trim() ...... $url = trim($url,"../"); ……但它给了我一个警告:
这个问题在这里已经有了答案: Java String trim has no effect (7 个答案) string trim function is not working [closed]
我有以下 XML: tag:search.twitter.com,2005:22204349686 如何将第二个冒号后的所有内容写入变量? 例如22204349686 最佳答案 if(preg_mat
修剪在深度优先搜索中什么时候停止有效?我一直在研究一种有效的方法来解决 N-Queens 问题,并且我第一次关注修剪。我已经为前两行实现了它,但它什么时候停止有效?我应该修剪多远? 最佳答案 N 皇后
我有一个图表,按天将两种类型的数据制成表格,我希望只修剪图表中的第一个和最后一个标签。这是一个可重现的数据示例: library(dplyr) library(ggplot2) library(sca
如何去掉 excel 中的前导空格? 我有很多行有这个问题。 最佳答案 在您的空格删除请求中,请注意: TRIM仅删除字符 32,即标准空格。 CLEAN将删除非打印空格,例如回车符(字符 13)和换
当前正在编写指令,并且需要将空格作为字符传递给它。 喜欢: 结果证明 angular 消除了前导空间;但我想保留它。 有什么办法吗? 编辑:我将指令参数作为字符串传递(使用@,而不是作为变量,使用=
我正在为一个使用 Bold for Delphi 对象持久性框架的应用程序的数据库做一些维护。该数据库已经投入生产多年,其中一些表已经变得非常大。其中之一是 BOLD_CLOCKLOG这与 Bold
如何“修剪” NSString 以便仅用旧字符串的特定部分创建新字符串? 例如,我有字符串“Monday the 12th of September”,我如何仅选出“Monday”部分? 最佳答案 使
我是一名优秀的程序员,十分优秀!