sizeof

2019-2020-1 20175310 20175317 20175320 实验三 实时系统

感情迁移 提交于 2019-12-05 11:28:42
2019-2020-1 20175310 20175317 20175320 实验三 实时系统 小组成员 20175310 奚晨妍 20175317 钟睿文 20175320 龚仕杰 实验步骤 一、并发程序-1 学习使用Linux命令wc(1) 基于Linux Socket程序设计实现wc(1)服务器(端口号是你学号的后6位)和客户端 客户端传一个文本文件给服务器 服务器返加文本文件中的单词数 上方提交代码 附件提交测试截图,至少要测试附件中的两个文件 client.c #include<netinet/in.h> // sockaddr_in #include<sys/types.h> // socket #include<sys/socket.h> // socket #include<stdio.h> // printf #include<stdlib.h> // exit #include<string.h> // bzero #define SERVER_PORT 175317 #define BUFFER_SIZE 1024 #define FILE_NAME_MAX_SIZE 512 int main() { // 声明并初始化一个客户端的socket地址结构 struct sockaddr_in client_addr; bzero(&client_addr,

2019-2020-1 20175311 20175324 20175330 实验三实时系统

此生再无相见时 提交于 2019-12-05 11:21:59
2019-2020-1 20175311 20175324 20175330 实验三实时系统 任务一 学习使用Linux命令wc(1) 基于Linux Socket程序设计实现wc(1)服务器(端口号是你学号的后6位)和客户端 客户端传一个文本文件给服务器 服务器返加文本文件中的单词数 使用多线程实现wc服务器并使用同步互斥机制保证计数正确 实验操作 任务一 : 实现wc功能实现 客户端给服务器传文件功能 在客户端调用wc函数统计传过来的文件的单词个数 wc命令参数:- 用wc命令做到只打印统计数字不打印文件名:cat test.txt |wc -l -c 统计字节数。 -l 统计行数。 -m 统计字符数。这个标志不能与 -c 标志一起使用。 -w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。 -L 打印最长行的长度。 -help 显示帮助信息 --version 显示版本信息 服务器代码: #include <netinet/in.h> // for sockaddr_in #include <sys/types.h> // for socket #include <sys/socket.h> // for socket #include <stdio.h> // for printf #include <stdlib.h> // for exit

希尔排序

感情迁移 提交于 2019-12-05 10:54:14
#include <iostream> #include <stdio.h> using namespace std; int g_szArray[] = { 7, 3, 5, 8, 9, 1, 2, 4, 6 }; void main() { int nLen = sizeof(g_szArray) / sizeof(g_szArray[0]); int nStep = nLen / 2; while (nStep >= 1) { for (int i = 0; i < nLen; i++) { if (i + nStep > nLen - 1) { break; } if (g_szArray[i] > g_szArray[i + nStep]) { g_szArray[i] = g_szArray[i] + g_szArray[i + nStep]; g_szArray[i + nStep] = g_szArray[i] - g_szArray[i + nStep]; g_szArray[i] = g_szArray[i] - g_szArray[i + nStep]; } } nStep = nStep / 2; } for (int i = 0; i < nLen; i++) { printf("%d ", g_szArray[i]); } printf("\n");

Is it safe to assert(sizeof(A) == sizeof(B)) when A and B are “the same”?

谁说胖子不能爱 提交于 2019-12-05 10:21:16
问题 Suppose I have two classes that I would expect to have exact same memory layout: struct A { int x; int y; }; /* possibly more code */ struct B { int a; int b; }; Is there anything in the standard that guarantees that I can safely static_assert(sizeof(A) == sizeof(B)) ? As a weaker variant consider struct C { int a; }; static_assert( sizeof(A) >= sizeof(C) ); // can this ever fail? static_assert( sizeof(A) > sizeof(C) ); // can this ever fail? The question was triggered by this one. Naively I

sizeof与strlen

寵の児 提交于 2019-12-05 09:43:10
#include <stdio.h> #include <string.h> #include<stdlib.h> void testArr(const char str[]) { printf("%lu %lu\n", sizeof(str), strlen(str)); } int main(void) { char str[] = "hello"; printf("test0 %lu %lu\n\n", sizeof(str), strlen(str)); char str1[8] = "hello"; printf("test1 %lu %lu\n\n", sizeof(str1), strlen(str1)); char str2[] = { 'h','e','l','l','o' }; printf("test2 %lu %lu\n\n", sizeof(str2), strlen(str2)); char *str3 = "hello"; printf("test3 %lu %lu\n\n", sizeof(str3), strlen(str3)); char str4[] = "hello"; testArr(str4); char str5[] = "hell\0o"; printf("test5 %lu %lu\n", sizeof(str5), strlen

2019-2020-1 20175310 20175317 20175320 实验三 实时系统

心已入冬 提交于 2019-12-05 09:07:48
2019-2020-1 20175310 20175317 20175320 实验三 实时系统 小组成员 20175310 奚晨妍 20175317 钟睿文 20175320 龚仕杰 实验步骤 一、并发程序-1 学习使用Linux命令wc(1) 基于Linux Socket程序设计实现wc(1)服务器(端口号是你学号的后6位)和客户端 客户端传一个文本文件给服务器 服务器返加文本文件中的单词数 上方提交代码 附件提交测试截图,至少要测试附件中的两个文件 client.c #include<netinet/in.h> // sockaddr_in #include<sys/types.h> // socket #include<sys/socket.h> // socket #include<stdio.h> // printf #include<stdlib.h> // exit #include<string.h> // bzero #define SERVER_PORT 175317 #define BUFFER_SIZE 1024 #define FILE_NAME_MAX_SIZE 512 int main() { // 声明并初始化一个客户端的socket地址结构 struct sockaddr_in client_addr; bzero(&client_addr,

Custom byte size?

妖精的绣舞 提交于 2019-12-05 08:57:50
So, you know how the primitive of type char has the size of 1 byte? How would I make a primitive with a custom size? So like instead of an in int with the size of 4 bytes I make one with size of lets say 16. Is there a way to do this? Is there a way around it? Normally you'd just make a struct that represents the data in which you're interested. If it's 16 bytes of data, either it's an aggregate of a number of smaller types or you're working on a processor that has a native 16-byte integral type. If you're trying to represent extremely large numbers, you may need to find a special library that

Does sizeof(float) always equal to sizeof(int) on all architectures?

喜欢而已 提交于 2019-12-05 08:56:58
I'm seeing code allocating memory for float using sizeof(int) . I'm wondering whether sizeof(float) always equal to sizeof(int) on all architectures? float *pointer2Float = (float *) USER_DEFINED_MALLOC (...,..., sizeof(int)) Note: this USER_DEFINED_MALLOC isa wrapper for conventional malloc, I think. Thanks Regards No, there are implementations (mainly embedded systems) with 16-bit int and 32-bit float . And of course, the sizes are allowed to be quite different per the standard. The sizes of ALL types (except char , signed char and unsigned char 1 ) are implementation-defined. So it is not

1 bit per bool in Array C++

Deadly 提交于 2019-12-05 08:41:45
bool fp[81]; From my understanding fp should use ceil(81/8) bytes because it is in succession. Am I correct? How can I prove this? No, the sizeof your buffer is implementation defined. Refer the quote from the Standard below. Therefore the size you can expect is 81 * X where X is the size of bool, which is implementation defined. $5.3.3/1 - "The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function

Linux socket program Demo1(client & server)

瘦欲@ 提交于 2019-12-05 07:21:33
client and server Demo of socket. client send data to server. server send data to client. // this is client #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <assert.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> #include <string.h> #define BUFF_SIZE 1024 int main(int argc, char* argv[]) { if(argc<=2) { printf("usage:%s ip_address port_number \r\n", basename(argv[0])); return 1; } char* ip = argv[1]; int port = atoi(argv[2]); struct sockaddr_in address; bzero(&address, sizeof(address)); address.sin_family = AF_INET; address.sin