strcat

How to generate a constexpr version string from three integers (or perhaps a git/SVN commit/rev. string)?

橙三吉。 提交于 2019-12-29 04:01:11
问题 Say I have constexpr const std::uint8_t major = 1; constexpr const std::uint8_t minor = 10; constexpr const std::uint8_t bugfix = 0; and I want constexpr const char* version_string(){ ... } to return the equivalent of "1.10.0" in this example, how would I do it? I assume I'll need both of these, in constexpr : integer to string conversion string concatenation The problem is purely academic, and I see little to no use to actually have it constexpr other than "it's possible". I just can't see

My Output has some weird symbols displaying

蹲街弑〆低调 提交于 2019-12-25 14:38:12
问题 I had to a coding for my class. The coding is about asking the user to type their Name, age and id. An then the program should for a passcode based on the first 6 letter in their name, their age and the first two letter in their student id. The problem is the a unidentified symbol (╠╠╠╠╠╠╠╠╠╠╠╠╠╠ )in the output. Can anyone tell me why it is there>? Then it should calculate and display the lenght of the passcode. Here is the code: #include <stdio.h> #include <string.h> void main(void) { char

strcat alternative issue C++

主宰稳场 提交于 2019-12-25 08:38:29
问题 I am working on a project which was initially sampled in C but want to work on it in C++. There is a section where a strcat() is used, I have been told to use an alternative. I have found one here, but when I try those the compiler gives me the following error: error: invalid operands of types char*' and char*' to binary `operator+' Is there something I am doing wrong? Edit: Here's the portion of the code that doesn't work FILE *FileOpen(string *fname, string* mode){ FILE *fp; string *str = "

webbench源码阅读

[亡魂溺海] 提交于 2019-12-24 11:49:30
学习内容   一共五百多行代码,其中包含了linux编程常用的API。可以通过学习源码,把不熟悉的API练习练习。 1 如何使用webbench (1)查看参数帮助 (2)运行方法 即以上模拟30个客户端在30秒期间并发请求百度,结果如下: 每分钟平均有1532次请求连接,服务器每秒传输字节为4039230,在30秒期间请求连接成功为766次,失败0次。 2 源码常用函数练习 (1) 选项参数 int getopt_long(int argc, char * const argv[],const char *optstring, const struct option *longopts,int *longindex); 函数中的argc和argv通常直接从main()的两个参数传递而来。optsting是选项参数组成的字符串: option结构数组,option结构称为长选项表,其声明如下: struct option { const char *name; int has_arg; int *flag; int val; }; 结构中的元素解释如下: const char *name:选项名,前面没有短横线。譬如"help"、"verbose"之类。 int has_arg:描述长选项是否有选项参数,如果有,是哪种类型的参数,其值见下表: 符号常量 数值 含义 no

Appending character arrays using strcat does not work

戏子无情 提交于 2019-12-24 02:18:31
问题 Can some one tell me what's wrong with this code??? char sms[] = "gr8"; strcat (sms, " & :)"); 回答1: sms is an array of size 4 1 . And you're appending more char literals, which is going outside of the array, as the array can accommodate at max 4 chars which is already occupied by g, r, 8, \0 . 1. By the way, why exactly 4? Answer : Because that there is a null character at the end! If you mention the size of array as shown below, then your code is valid and well-defined. char sms[10] = "gr8";

Is it undefined behavior if the destination string in strcat function is not null terminated?

元气小坏坏 提交于 2019-12-23 01:36:19
问题 The following program // Code has taken from http://ideone.com/AXClWb #include <stdio.h> #include <string.h> #define SIZE1 5 #define SIZE2 10 #define SIZE3 15 int main(void){ char a[SIZE1] = "Hello"; char b[SIZE2] = " World"; char res[SIZE3] = {0}; for (int i=0 ; i<SIZE1 ; i++){ res[i] = a[i]; } strcat(res, b); printf("The new string is: %s\n",res); return 0; } has well defined behavior. As per the requirement, source string b is null terminated. But what would be the behavior if the line

c/c++之strcat函数

守給你的承諾、 提交于 2019-12-20 07:03:05
我们首先来看这样一段代码: # include <iostream> # include <string.h> using namespace std ; int main ( ) { char pointer [ 24 ] = "Hello,world" ; cout << "The length of pointer:" << strlen ( pointer ) << endl ; strcat ( pointer , "China." ) ; cout << pointer << endl ; strcpy ( pointer , "Hello,world" ) ; strcat ( pointer + 3 , "China." ) ; cout << pointer << endl ; strcpy ( pointer , "Hello,world" ) ; strcat ( pointer + 8 , "China." ) ; cout << pointer << endl ; strcpy ( pointer , "Hello,world" ) ; strcat ( pointer + 11 , "China." ) ; cout << pointer << endl ; strcpy ( pointer , "Hello,world" ) ; strcat (

Socket网络编程--小小网盘程序(5)

核能气质少年 提交于 2019-12-19 08:59:46
  各位好呀!这一小节应该就是这个小小网盘程序的最后一小节了,这一节将实现最后的三个功能,即列出用户在服务器中的文件列表,还有删除用户在服务器中的文件,最后的可以共享文件给好友。   列出用户在服务器中的文件列表   增加一个结构体 1 struct FileList 2 { 3 int cnt; 4 char list[16][128]; 5 };   为了方便我就假设服务器最多可以存16个单个用户的文件。如果想要支持更多的文件,这里可以增加一个int pages;用于分页作用,我们在服务器中获取文件时,可以根据分页进行发送。这样既方便又能支持多文件。   client.cpp这个客户端文件增加一个函数 1 int file_list(struct Addr addr,struct User user) 2 { 3 struct sockaddr_in servAddr; 4 struct hostent *host; 5 struct Control control; 6 struct FileList filelist; 7 int sockfd; 8 9 host=gethostbyname(addr.host); 10 servAddr.sin_family=AF_INET; 11 servAddr.sin_addr=*((struct in_addr *)host->h

strcat implementation

本秂侑毒 提交于 2019-12-18 11:59:09
问题 I tried to implement the strcat by myself, and I found the strcat implementation from Wiki like this......but when I use it, there is segmentation fault. What's wrong with the code below? char * strcat(char *dest, const char *src) { size_t i,j; for (i = 0; dest[i] != '\0'; i++) ; for (j = 0; src[j] != '\0'; j++) dest[i+j] = src[j]; dest[i+j] = '\0'; return dest; } 回答1: the code is okay. Looks like you have a problem in the calling code. Did you remember to allocate enough memory for the

strcat concat a char onto a string?

我是研究僧i 提交于 2019-12-18 03:33:53
问题 Using GDB, I find I get a segmentation fault when I attempt this operation: strcat(string,&currentChar); Given that string is initialized as char * string = ""; and currentChar is char currentChar = 'B'; Why does this result in a segmentation fault? If strcat can't be used for this, how else can I concat a char onto a string? 回答1: Because &currentChar is not a string, it doesn't finish with \0 character. You should define B as char *currentChar = 'B'; . Also according to http://www.cplusplus