小编Jam*_*red的帖子

字符串比较不工作C.

我今天在c编程中遇到了一个奇怪的问题.我为服务器客户端通信编写了一个程序并在其上应用了字符串比较函数,但是如果我将字符串与buf中的东西进行比较,则该函数不起作用.我还检查了buf中的数据是否与我在几次迭代后输入的数据不同但结果是否定的且数据与我输入的数据相同.那为什么不起作用strcmp.这是代码:

char buf[1024];
while(1)
{
    int readbytes=read(communFd,buf,1024);

    write(STDOUT_FILENO,buf,readbytes);


   if(!strcmp(buf,"exitChat"))
    {
        printf("Chat terminating...\n");
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

问候

c string string-comparison

0
推荐指数
1
解决办法
888
查看次数

计算输入

我想在8位输入中计算1的数量,并输出其中有多少个.我发现这种方式非常粗糙和冗余.我想知道是否有任何简单而好的方法可以找到它们.我的代码看起来像:

module 8to4bit(in,out);

input [7:0]in;
output [3:0]out;


assign out=(input == 1 || input == 2 || input == 4 || input == 8 || input == 16 || input == 32 || input == 64 || input == 128)?1:
(input == 3 || input == 5 || input == 6 || input == 9 || input == 10 || input == 12 || input == 24 || input == 128)?2:0;
Run Code Online (Sandbox Code Playgroud)

... 8位输入中的所有1都相同.

找到它们有简单的方法吗?

问候

verilog

0
推荐指数
1
解决办法
141
查看次数

标签 统计

c ×1

string ×1

string-comparison ×1

verilog ×1