char

Returning char * instead of string

回眸只為那壹抹淺笑 提交于 2021-01-29 05:36:52
问题 How may I correct the following code in C++11: const char *what() const noexcept override { return "Mtm matrix error: Dimension mismatch: (" + std::to_string(mat1_height) + "," + std::to_string(mat1_width) + ") (" + std::to_string(mat2_height) + "," + std::to_string(mat2_width) + ")"; } As you can see I'm returning string instead of const char* but won't that be converrted automatically? and how to fix that? Note: I want something to look like c++ code and not c using sprintf for example 回答1:

Comparing Characters (ARM Assembly)

泄露秘密 提交于 2021-01-29 04:28:30
问题 I'm trying to compare a Character from a Char-Array with a char in my assembly code. This is the C-Code I use to start the assembly code: char a[] = "abc"; char b = 'a'; int size = 3; int d = _asm_main(a); printf("Char a: %s\n",a); printf("Erg:%d\n",d); and this is the assembly code: _asm_main: push {r6,r7,r8,lr} mov r8,r0 ldr r7,[r8,#2] mov r6,r7 b compare compare: cmp r6,#'c' beq true b false true: mov r0,#1 b end false: mov r0,#2 b end end: pop {r6,r7,r8,pc} BX lr It works for 'c' but if I

sscanf_s doesn't return first character of string

无人久伴 提交于 2021-01-28 18:38:42
问题 I'm trying to find the first string (max 4 characters) in a comma-separated list of strings inside a C char-array. I'm trying to achieve this by using sscanf_s (under Windows) and the format-control string %[^,] : char mystring[] = "STR1,STR2"; char temp[5]; if (sscanf_s(mystring, "%[^,]", temp, 5) != 0) { if (strcmp(temp, "STR1") == 0) { return 0; } else if (strcmp(temp, "STR2") == 0) { return 1; } else { return -1; } } After calling sscanf_s the content of temp is not STR1 but \0TR1 ( \0

Using unsigned char instead of char because of its range

怎甘沉沦 提交于 2021-01-28 12:14:04
问题 I've been working on a small pure C client application (my first :/) which uses TCP socket for communication with the server. The Server sends me a packet (C structure) in which the first byte contains the size of the packet. The problem is that server is using unsigned char to represent the size of the packet because char is signed (from -128 to +127) and +127 is not enough to represent size that can be up to 255 in some packets. => I need a unsigned char buffer; In Linux, the second

How am I allowed to workaround DOS functions that used strings containing accented characters (ASCII to UTF-8)?

瘦欲@ 提交于 2021-01-28 09:12:01
问题 I was writing a SW where I wanted to use an old C code written in the early '80. This code did some conversion on strings. It also used the accented characters that, at that time (DOS), were coded in the ASCII table (codes bigger than 127). Now the new systems use UTF-8 encoding, so the old code works very badly. I am using Linux (Ubuntu 17 / gcc gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0). I'm looking for a workaround allowing me to make the least possible changes. I have begun to do some tests to

Dealing with char values over 127 in C

醉酒当歌 提交于 2021-01-28 04:51:25
问题 I'm quite new to C programming, and I have some problems trying to assign a value over 127 (0x7F) in a char array. In my program, I work with generic binary data and I don't face any problem printing a previously acquired byte stream (e.g. with fopen or fgets, then processed with some bitwise operations) as %c or %d. But if I try to print a character from its numerical value like this: printf("%c\n", 128); it just prints FFFD (the replacement character). Here is another example: char abc[] =

Modifying a String (char array) [closed]

老子叫甜甜 提交于 2021-01-28 03:23:00
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 months ago . Improve this question I am trying to modify a string in C language char signal_cat[8]; if (k == 1) { strcpy_s(signal_cat, "HPHA",6); //why cant I change char array (string) values??? } else if (k == 2) { strcpy_s(signal_cat, "Normal",6); } printf("Original signal category: %s \n", signal_cat); When

Modifying a String (char array) [closed]

我的梦境 提交于 2021-01-28 02:12:14
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 months ago . Improve this question I am trying to modify a string in C language char signal_cat[8]; if (k == 1) { strcpy_s(signal_cat, "HPHA",6); //why cant I change char array (string) values??? } else if (k == 2) { strcpy_s(signal_cat, "Normal",6); } printf("Original signal category: %s \n", signal_cat); When

how to display a number that is a char

孤街醉人 提交于 2021-01-27 21:03:43
问题 I have a multi-dimensional array of chars that I want to display. one of the dimensions has numbers in it (0, 1, 2, etc.). When I go to display the array, I get the ascii results. I realize the char output works as defined (char + number = ascii) but I was looking to specifically show the number. Ex. char a = 3; cout << a; // gives me # I want to display 3. I have tried casting to an int: cout << (int)a; I have tried casting inside the array myArray[(int)a]; Neither of those have seemed to

C: Printing from char array produces erroneous characters

≯℡__Kan透↙ 提交于 2021-01-27 19:15:51
问题 Solutions for K. N. King's C Programming: A Modern Approach, 2nd Edition , Chapter 8, Programming Project 14, produces different outputs both correct and incorrect. Examples shown below: Reversal of sentence: you can't swallow a cage can you? Reversal of sentence: you can't swallow a cage can you�(�? Reversal of sentence: you can't swallow a cage can you��x�? Reversal of sentence: you can't swallow a cage can you�Ց�? As shown by the example input, correct output should be: Enter a sentence: