Using write() system call to output dec/hex value of char array bufffer
Date : March 29 2020, 07:55 AM
I wish this help you You could make a larger buffer, make the conversion from ASCII to hex/dec (as needed) in that and print the new one. I hope this example illustrates the idea: #include <stdlib.h>
#include <io.h>
int main (int argc, char** argv)
{
const char* pHexLookup = "0123456789abcdef";
char pBuffer[] = {'a', 'b', 'c'}; // Assume buffer is the contents of the file you have already read in
size_t nInputSize = sizeof(pBuffer); // You will set this according to how much your input read in
char* pOutputBuffer = (char*)malloc(nInputSize * 3); // This should be sufficient for hex, since it takes max 2 symbols, for decimal you should multiply by 4
for (size_t nByte = 0; nByte < nInputSize; ++nByte)
{
pOutputBuffer[3 * nByte] = pBuffer[nByte];
pOutputBuffer[3 * nByte + 1] = pHexLookup[pBuffer[nByte] / 16];
pOutputBuffer[3 * nByte + 2] = pHexLookup[pBuffer[nByte] % 16];
}
write(1 /*STDOUT_FILENO*/, pOutputBuffer, nInputSize * 3);
free(pOutputBuffer);
return EXIT_SUCCESS;
}
|
Why does `System.out.println(null);` give "The method println(char[]) is ambiguous for the type PrintStream error&q
Tag : java , By : user116330
Date : March 29 2020, 07:55 AM
will help you There are 3 println methods in PrintStream that accept a reference type - println(char x[]), println(String x), println(Object x). When you pass null, all 3 are applicable. The method overloading rules prefer the method with the most specific argument types, so println(Object x) is not chosen. System.out.println((String)null);
|
Automapper says Missing map from System.String to System.Char? But I see no Char property
Tag : chash , By : Gerhard Miller
Date : March 29 2020, 07:55 AM
Hope this helps The solution is to explicitly set mapping for the Departments and Titles fields: CreateMap<UserReport, UserModel>()
.ForMember(x => x.Departments, o => o.MapFrom(s => string.Join("\n", s.Departments)))
.ForMember(x => x.Titles, o => o.MapFrom(s => string.Join("\n", s.Titles)));
IEnumerable<string> => IEnumerable<char>
|
Convert Char Input to Decimal Output - dont understand
Date : March 29 2020, 07:55 AM
it should still fix some issue 10 is the ASCII code of the newline character, '\n'. You input this character when you hit Enter.
|
Fill char array with input and I dont understand the output
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further So I'm learning the char arrays in C. I wrote a little program which works with functions and reads input from terminal and on EOF will printf the char array. , There are multiple problems in your code: #include <stdio.h>
const int MAXLENGTH = 10;
int getLine(char[], int);
int main(void) {
char inputString[MAXLENGTH];
getLine(inputString, MAXLENGTH);
printf("%s\n", inputString);
return 0;
}
// Functions:
int getLine(char destArray[], int length) {
int i, c;
for (i = 0; i < length - 1; i++) {
c = getchar();
if (c == EOF || c == '\n')
break;
destArray[i] = c;
}
destArray[i] = '\0';
return i;
}
|