char

Reverse a string without strtok in C

给你一囗甜甜゛ 提交于 2021-02-08 11:13:01
问题 Working on a program that uses RPN (Reverse Polish Notation). I have a function that reverses all the words of string without using strtok or triggering printf (unlike all the solutions found online and here). The function actually works partially as it prints all the words of a given string except the last one and I need help figuring out what's going on. char *extract(char s[]) { if (s[0] == '\0') return NULL; int i = 0; char *p = NULL; while (s[i] != '\0') { if (s[i] == ' ') p = s + i; i++

How to convert multi-character constant to integer in C?

与世无争的帅哥 提交于 2021-02-08 06:44:52
问题 How to convert multi-character constant in x to integer? I tried for example '13' as ('3' + '1' << 3) , but it doesn't work properly. I don't mean "0123" , but '0123' . It compiles, but I don't how did compiler gets the octal result 6014231063 when printing it. I am not looking for atoi which just converts this to present number. For example int x = '1' would print 49 in decimal number system. Now I am interested what would print int x = '0123' . This task is from programming competition, so

How to convert multi-character constant to integer in C?

半世苍凉 提交于 2021-02-08 06:44:27
问题 How to convert multi-character constant in x to integer? I tried for example '13' as ('3' + '1' << 3) , but it doesn't work properly. I don't mean "0123" , but '0123' . It compiles, but I don't how did compiler gets the octal result 6014231063 when printing it. I am not looking for atoi which just converts this to present number. For example int x = '1' would print 49 in decimal number system. Now I am interested what would print int x = '0123' . This task is from programming competition, so

In C# how to get minimum and maximum value of char printed in Unicode format?

廉价感情. 提交于 2021-02-08 06:14:33
问题 According to MSDN the minimum value of char is U+0000 and maximum value of char is U+ffff I have written the following code to print the same: using System; using System.Collections.Generic; using System.Linq; namespace myApp { class Program { static void Main() { char min = char.MinValue; char max = char.MaxValue; Console.WriteLine($"The range of char is {min} to {max}"); } } } But I am not getting the output in the format U+0000 and U+ffff. How to get it? 回答1: Your problem is that char when

Are chars automatically promoted in C expressions?

元气小坏坏 提交于 2021-02-07 19:18:06
问题 I made a statement to a colleague of mine, which was: "chars are automatically promoted to integers in C expressions, and that's fine for performance since CPUs work fastest with their natural word size. I believe char promotion behavior is stated somewhere in the standard due to a char's rank. This is the response I got back: "Characters are not default promoted to an integer. The register size is 32 bit, but multiple byte values in a row can be packed into a single register as a compiler

Are chars automatically promoted in C expressions?

拥有回忆 提交于 2021-02-07 19:16:20
问题 I made a statement to a colleague of mine, which was: "chars are automatically promoted to integers in C expressions, and that's fine for performance since CPUs work fastest with their natural word size. I believe char promotion behavior is stated somewhere in the standard due to a char's rank. This is the response I got back: "Characters are not default promoted to an integer. The register size is 32 bit, but multiple byte values in a row can be packed into a single register as a compiler

is there a way to set the length of a std::string without modifying the buffer content?

最后都变了- 提交于 2021-02-07 12:36:33
问题 According to the statements made in the answers of these questions Is writing to &str[0] buffer (of a std:string) well-defined behaviour in C++11? Is it legal to write to std::string? writing directly to std::string internal buffers .. in C++11 it should be possible to call a C API function which takes a char pointer to store the output like this: str::string str; str.reserve(SOME_MAX_VALUE); some_C_API_func(&str[0]); But is there now a legal way to set the size of the string to the length of

ord, md5 shows different behaviour on @

人走茶凉 提交于 2021-02-07 10:58:50
问题 I used ord to check @ and @‪ are same char. But ord output the same value while md5 does not. php -a Interactive shell php > echo ord('@'); 64 php > echo ord('@‪'); 64 php > echo md5('@'); 518ed29525738cebdac49c49e60ea9d3 php > echo md5('@‪'); e6124653b6620abe51d7c401a7644674 php > Here is the screenshot, 回答1: Your second one is @ followed by U+202A - LEFT-TO-RIGHT EMBEDDING . As they are different strings, naturally they have different MD5 encodings. php > echo md5("@\u{202a}");

*Might* an unsigned char be equal to EOF? [duplicate]

我们两清 提交于 2021-02-07 05:44:13
问题 This question already has answers here : Can sizeof(int) ever be 1 on a hosted implementation? (8 answers) Closed 5 years ago . When using fgetc to read the next character of a stream, you usually check that the end-of-file was not attained by if ((c = fgetc (stream)) != EOF) where c is of int type. Then, either the end-of-file has been attained and the condition will fail, or c shall be an unsigned char converted to int , which is expected to be different from EOF —for EOF is ensured to be

Is it technically impossible to implement memcpy from scratch in Standard C?

一世执手 提交于 2021-02-07 05:11:59
问题 Howard Chu writes: In the latest C spec it is impossible to write a "legal" implementation of malloc or memcpy. Is this right? My impression is that in the past, the intent (at least) of the standard was that something like this would work: void * memcpy(void * restrict destination, const void * restrict source, size_t nbytes) { size_t i; unsigned char *dst = (unsigned char *) destination; const unsigned char *src = (const unsigned char *) source; for (i = 0; i < nbytes; i++) dst[i] = src[i];