- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须编写一个函数int bit_to_ascii(const char input[], char output[]);
,它从字符二进制代码数组中读取并翻译它。我已经这么做了。
当我在家用计算机上使用 Code::Blocks 时,一切正常。但是,当我将代码放在必须保留程序标记的服务器上时,它正在编译,但在程序的第一步之后给了我一个段错误。我能有什么错呢? Code::Blocks 中的编译器和服务器上的编译器有什么区别?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LINES 5
/* assignment #1 function prototype */
int bit_to_ascii(const char input[], char output[]);
int main( ) {
const char *core_data[ ] = {
"0", /* should insert the null byte '\0' only */
"01010111 This sequence contains the letter 'W' " /* 87 = 'W' */
" r5 0 #! 1 1 gP 0 f66-:] 0 [ } 1 v4t^ 0 1 n>?:77" /* 101 = 'e' */
" junk ^*@&#^% 0110 more junk }{r;,<> 1100 2x" /* 108 = 'l' */
" 0 1 1 0 0 011" /* 99 = 'c' */
"0 ^%jh 1 ]{) OVR 1 - 0 _! 9 + 1 118Y z(x pM1 " /* 111 = 'o' */
"This next group of 8 should be SKP skipped! 11111111 " /* skipped */
"*&^! 0 1 1 0 1 1 0 128673kjshd:L< 2938 " /* 109 = 'm' */
" r5 0 #! 1 1 gP 0 f66-:] 0 [ } 1 v4t^ 0 1 n>?:77" /* 101 = 'e' */
"#!/bin/bash 00 1 00 00 0 g^b-ps 6@&^% " /* 32 = ' ' */
"01010100 This sequence contains the letter 'T' " /* 84 = 'T' */
"0 ^%jh 1 ]{) OVR 1 - 0 _! 9 + 1 118Y z(x pM1 " /* 111 = 'o' */
"#!/bin/bash 00 1 00 00 0 g^b-ps 6@&^% " /* 32 = ' ' */
"---repeat--->0 1 0 0 1 1 1 1<------------RPT2--------" /* 79 = 'O' */
"0 1 0 1 0bbavac9872962 000&*************************" /* 80 = 'P' */
"a0b0c1d1e0f0g1h0ijklmnopqrstuvwxyz*******************" /* 50 = '2' */
"00fg333 110100>>>>>>>>" /* 52 = '4' */
"00fg333 110100>>>>>>>>" /* 52 = '4' */
" 0000 ",/* 0 = '\0' */
"00011110 This char should not be inserted! " /* 30 cntrl */
" 00011111 This char should not be inserted! " /* 31 cntrl */
" 00100000 " /* 32 = ' ' */
" 00100001 " /* 33 = '!' */
" 00100010 " /* 34 = '"' */
" 00100011 " /* 35 = '#' */
" 00100100 " /* 36 = '$' */
" 00100101 " /* 37 = '%' */
" 00100110 " /* 38 = '&' */
" 00100111 " /* 39 = ''' */
" 00101000 " /* 40 = '(' */
" 00101001 " /* 41 = ')' */
" 00101010 " /* 42 = '*' */
" 00101011 " /* 43 = '+' */
" 00101100 " /* 44 = ',' */
" 00101101 " /* 45 = '-' */
" 00101110 " /* 46 = '.' */
" 00101111 " /* 47 = '/' */
" 00110000 " /* 48 = '0' */
" 00110001 " /* 49 = '1' */
" 00110010 " /* 50 = '2' */
" 00110011 " /* 51 = '3' */
" 00110100 " /* 52 = '4' */
" 00110101 " /* 53 = '5' */
" 00110110 " /* 54 = '6' */
" 00110111 " /* 55 = '7' */
" 00111000 " /* 56 = '8' */
" 00111001 " /* 57 = '9' */
" 00111010 " /* 58 = ':' */
" 00111011 " /* 59 = ';' */
" 00111100 " /* 60 = '<' */
" 00111101 " /* 61 = '=' */
" 00111110 " /* 62 = '>' */
" 00111111 " /* 63 = '?' */
" 01000000 " /* 64 = '@' */
" 00000000 ",/* 0 = '\0'*/
" 01000001 " /* 65 = 'A' */
" 01000010 " /* 66 = 'B' */
" 01000011 " /* 67 = 'C' */
" 01000100 " /* 68 = 'D' */
" 01000101 " /* 69 = 'E' */
" 01000110 " /* 70 = 'F' */
" 01000111 " /* 71 = 'G' */
" 01001000 " /* 72 = 'H' */
" 01001001 " /* 73 = 'I' */
" 01001010" /* 74 = 'J' */
" 01001011 " /* 75 = 'K' */
" 01001100 " /* 76 = 'L' */
" 01001101 " /* 77 = 'M' */
" 01001110 " /* 78 = 'N' */
" 01001111 " /* 79 = 'O' */
" 01010000 " /* 80 = 'P' */
" 01010001 " /* 81 = 'Q' */
" 01010010 " /* 82 = 'R' */
" 01010011 " /* 83 = 'S' */
" 01010100 " /* 84 = 'T' */
" 01010101 " /* 85 = 'U' */
" 01010110 " /* 86 = 'V' */
" 01010111 " /* 87 = 'W' */
" 01011000 " /* 88 = 'X' */
" 01011001 " /* 89 = 'Y' */
" 01011010 " /* 90 = 'Z' */
" 01011011 " /* 91 = '[' */
" 01011100 " /* 92 = '/' */
" 01011101 " /* 93 = ']' */
" 01011110 " /* 94 = '^' */
" 01011111 " /* 95 = '_' */
" 01100000 " /* 96 = '`' */
" 00000000 ",/* 0 = '\0'*/
" 01100001 " /* 97 = 'a' */
" 01100010 " /* 98 = 'b' */
" 01100011 " /* 99 = 'c' */
" 01100100 " /* 100 = 'd' */
" 01100101 " /* 101 = 'e' */
" 01100110 " /* 102 = 'f' */
" 01100111 " /* 103 = 'g' */
" 01101000 " /* 104 = 'h' */
" 01101001 " /* 105 = 'i' */
" 01101010 " /* 106 = 'j' */
" 01101011 " /* 107 = 'k' */
" 01101100 " /* 108 = 'l' */
" 01101101 " /* 109 = 'm' */
" 01101110 " /* 110 = 'n' */
" 01101111 " /* 111 = 'o' */
" 01110000 " /* 112 = 'p' */
" 01110001 " /* 113 = 'q' */
" 01110010 " /* 114 = 'r' */
" 01110011 " /* 115 = 's' */
" 01110100 " /* 116 = 't' */
" 01110101 " /* 117 = 'u' */
"01110110 " /* 118 = 'v' */
" 01110111 " /* 119 = 'w' */
" 01111000 " /* 120 = 'x' */
" 01111001 " /* 121 = 'y' */
" 01111010 " /* 122 = 'z' */
" 01111011 " /* 123 = '{' */
" 011111RPT10 " /* 124 = '|' */
" 01111101 " /* 125 = '}' */
" 00000000 " /* 0 = '\0'*/
};
char phrase[41];
char correct[LINES][41] = {
"",
"Welcome To OOP244",
" !\"#$%&'()*+,-./0123456789:;<=>?@",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`",
"abcdefghijklmnopqrstuvwxyz{||||||||||}"
};
int rvalues[LINES] = { 1, 18, 34, 33, 39 }, i;
int valid = 1, rc;
for(i=0; i<LINES && valid; i++) {
rc = bit_to_ascii(core_data[i], phrase);
if(rc != rvalues[i] || strcmp(phrase, correct[i])) {
printf("Failed on test... %d\n\n", i+1);
valid = 0;
}
else {
printf("Passed test %d...\n\n", i+1);
}
printf("Your string ----------> '%s'\n", phrase);
printf("Actual string --------> '%s'\n", correct[i]);
printf("Your return value ----> %d\n", rc);
printf("Actual return value --> %d\n", rvalues[i]);
printf("Press the ENTER key to continue...");
getchar( );
}
if(valid) {
printf("\nCongratualtions!!! You passed all tests.\n");
printf("You may hand in your assignment.\n");
}
else {
printf("\nYou correctly sequenced %d/5 data blocks...\n", i-1);
printf("Your program still needs some work!\n");
printf("Keep at it!\n\n");
}
return 0;
}
int bit_to_ascii(const char core[ ], char data[ ]) {
int i, rc = 0, j, inte[7], len, len2, m, rpt1, rptcounter, bin, lendata = 0, p = 0;
char binarray[9], rpt[4], skp[9];
rpt[4]='\0';
for(i=0, j=0; core[i] != '\0'; i++) {
switch(core[i]) {
case '1':
case '0':
if(j<8) {
binarray[j++] = core[i];
binarray[j] = '\0';
}
else {
binarray[j] = '\0';
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
bin = inte[0] + inte[1] + inte[2] + inte[3] + inte[4] + inte[5] + inte[6] +inte[7];
if(bin<=0 || bin >=32) {
data[lendata] = bin;
lendata++;
}
j = 0; /* resets j to 0 after 8 1's or 0's have been found */
if(j<8) {
binarray[j++] = core[i];
}//end if
}//end else
case 'R':
if(core[i+1] == 'P' && core[i+2] == 'T') {
i=i+3;
if(isdigit(core[i])) {
rpt[0] = core[i];
i++;
if(isdigit(core[i])) {
rpt[1] = core[i];
i++;
if(isdigit(core[i])) {
rpt[2] = core[i];
i++;
}
}
rpt1 = atoi (rpt);
//printf("\n\n%d\n\n", rpt1);
len = strlen(binarray);
for(rptcounter=0, j=0; rptcounter<rpt1; rptcounter++ ){ //loops rpt1 times
if(len<8){
len2 = 8 - len;
m = len;
do {
binarray[m]='0';
m++;
}while (m != 8);
}
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
bin = inte[0] + inte[1] + inte[2] + inte[3] + inte[4] + inte[5] + inte[6]+inte[7];
data[lendata] = bin;
lendata++;
}
}
}
break;
case 'S':
if(core[i+1] == 'K' && core[i+2] == 'P') {
i=i+3;
for(p=0;p!=8;i++) {
switch(core[i]) {
case '1':
case '0':
skp[p] = core[i];
p++;
break;
}
}
}
break;
}//end case
}//end for
binarray[j] = '\0';
len = strlen(binarray);
if(len<8){
len2 = 8 - len;
m = len;
do {
binarray[m]='0';
m++;
}while (m != 8);
}
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
bin = inte[0] + inte[1] + inte[2] + inte[3] + inte[4] + inte[5] + inte[6] + inte[7];
data[lendata] = bin;
lendata++;
data[lendata]='\0';
rc = strlen(data) + 1;
if (rc==0) {
rc++;
}
return rc;
}
最佳答案
另一个跳出来的问题是
char binarray[9], rpt[4], skp[9];
rpt[4]='\0';
尽管有效索引为 0-3,但您将 rpt[4]
设置为 0。
您正在写入 inte
的八个元素,
inte[0] = (binarray[0] - 48) * 128;
inte[1] = (binarray[1] - 48) * 64;
inte[2] = (binarray[2] - 48) * 32;
inte[3] = (binarray[3] - 48) * 16;
inte[4] = (binarray[4] - 48) * 8;
inte[5] = (binarray[5] - 48) * 4;
inte[6] = (binarray[6] - 48) * 2;
inte[7] = (binarray[7] - 48) * 1;
尽管它被声明为int i, rc = 0, j, inte[7], ...
。
关于c - 与 C 赋值堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10789561/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!