Search Results

Search found 5202 results on 209 pages for 'char'.

Page 8/209 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • dynamic char array sizing

    - by droseman
    Hello, In my application, I have a char array defined which can take one of three options: "okay", "high", "low" which are then sent down a serial port to a remote device. I currently have the array sized to take the 4 character words plus carriage return and line feed, but when I have to send "low" I get a null character in the strings, which I am concerned would confuse the host terminal. array definition char mod1_status_char[6] = {'0','0','0','0','0','0'}; char mod2_status_char[6] = {'0','0','0','0','0','0'}; char mod3_status_char[6] = {'0','0','0','0','0','0'}; sample of switch case statement: void DCOKStatus(uint8_t *ptr_status) { uint8_t status = *ptr_status; switch (status) { case 0x00: strcpy(mod1_status_char, "okay"); strcpy(mod2_status_char, "okay"); strcpy(mod3_status_char, "okay"); break; case 0x10: strcpy(mod1_status_char, "okay"); strcpy(mod2_status_char, "okay"); strcpy(mod3_status_char, "low"); break; } This is the struct which makes the message string to send strcpy(MsgStatus_on.descriptor_msg, "$psu_"); MsgStatus_on.address01 = hex_addr[0]; MsgStatus_on.address02 = hex_addr[1]; MsgStatus_on.space01 = 0x20; strcpy(MsgStatus_on.cmdmsg01, "op_en op1_"); strcpy(MsgStatus_on.statusmsg01, mod1_status_char); MsgStatus_on.space02 = 0x20; strcpy(MsgStatus_on.cmdmsg02, "op2_"); strcpy(MsgStatus_on.statusmsg02, mod2_status_char); MsgStatus_on.space03 = 0x20; strcpy(MsgStatus_on.cmdmsg03, "op3_"); strcpy(MsgStatus_on.statusmsg03, mod3_status_char); MsgStatus_on.CR = 0x0D; MsgStatus_on.LF = 0x0A; and this sends the message void USARTWrite(char *object, uint32_t size) { GPIO_SetBits(GPIOB, GPIO_Pin_1); char *byte; for (byte = object; size--; ++byte) { USART_SendData(USART1,*byte); } Would anyone be able to suggest a good approach to dynamically size the array to one character shorter when I need to send "low"? Thanks

    Read the article

  • When does printf("%s", char*) stop printing?

    - by remagen
    In my class we are writing our own copy of C's malloc() function. To test my code (which can currently allocate space fine) I was using: char* ptr = my_malloc(6*sizeof(char)); memcpy(ptr, "Hello\n", 6*sizeof(char)); printf("%s", ptr); The output would typically be this: Hello Unprintable character Some debugging figured that my code wasn't causing this per say, as ptr's memory is as follows: [24 bytes of meta info][Number of requested bytes][Padding] So I figured that printf was reaching into the padding, which is just garbage. So I ran a test of: printf("%s", "test\nd"); and got: test d Which makes me wonder, when DOES printf("%s", char*) stop printing chars?

    Read the article

  • How to implement " char * ftoa(float num) " without sprintf() library function in C, C++ and JAVA

    - by SIVA
    Today I appeared for an interview, and the question was writing my own "char * ftoa(float num) " in C, C++ and Java. Yes, I know float numbers follow IEEE standard while allocating their memory, but I don't know float to char conversion by using Mantissa and Exponent in C. I don't have any idea to solve the above problem in C++ and JAVA. I/P to the ftoa(): 1.23 O/P from the ftoa(): 1.23 (char format). Thanks in advance ...

    Read the article

  • QT:QString to char conversion

    - by mawia
    hi! all, I was tryin to convert a QSting to char* type but by following methods,but those does'nt seem to work. // QLineEdit *line=new QLineEdit();{just to describe what is line here} QString temp=line->text(); char *str=(char *)malloc(10); QByteArray ba=temp.toLatin1(); strcpy(str,ba.data()); can you elobrate the possible flaw with this method ,or tell alternative method.

    Read the article

  • SQL: ATER COLUMN to shorter CHAR(n) type

    - by Rising Star
    I'm working with MS SQL SERVER 2003. I want to change a column in one of my tables to have fewer characters in the entries. This is identical to this question: http://stackoverflow.com/questions/2281336/altering-a-table-column-to-accept-more-characters except for the fact that I want fewer characters instead of more. I have a column in one of my tables that holds nine-digit entries. A developer previously working on the table mistakenly set the column to hold ten-digit entries. I need to change the type from CHAR(10) to CHAR(9). Following the instructions from the discussion linked above, I wrote the statement ALTER TABLE [MY_TABLE] ALTER COLUMN [MY_COLUMN] CHAR(9); This returns the error message "String or binary data would be truncated". I see that my nine-digit strings have a space appended to make them ten digits. How do I tell SQL Server to discard the extra space and convert my column to a CHAR(9) type?

    Read the article

  • vector<string> or vector<char *>?

    - by Aaron
    Question: What is the difference between: vector<string> and vector<char *>? How would I pass a value of data type: string to a function, that specifically accepts: const char *? For instance: vector<string> args(argv, argv + argc); vector<string>::iterator i; void foo (const char *); //*i I understand using vector<char *>: I'll have to copy the data, as well as the pointer Edit: Thanks for input!

    Read the article

  • Haskell: variant of `show` that doesn't wrap String and Char in quotes

    - by Joey Adams
    I'd like a variant of show (let's call it label) that acts just like show, except that it doesn't wrap Strings in " " or Chars in ' '. Examples: > label 5 "5" > label "hello" "hello" > label 'c' "c" I tried implementing this manually, but I ran into some walls. Here is what I tried: {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} module Label where class (Show a) => Label a where label :: a -> String instance Label [Char] where label str = str instance Label Char where label c = [c] -- Default case instance Show a => Label a where label x = show x However, because the default case's class overlaps instance Label [Char] and instance Label Char, those types don't work with the label function. Is there a library function that provides this functionality? If not, is there a workaround to get the above code to work?

    Read the article

  • Convert wchar_t to char

    - by Yan Cheng CHEOK
    I was wondering is it safe to do so? wchar_t wide = /* something */; assert(wide >= 0 && wide < 256 &&); char myChar = static_cast<char>(wide); If I am pretty sure the wide char will fall within ASCII range.

    Read the article

  • copying a short int to a char array

    - by cateof
    I have a short integer variable called s_int that holds value = 2 unsighed short s_int = 2; I want to copy this number to a char array to the first and second position of a char array. Let's say we have char buffer[10];. We want the two bytes of s_int to be copied at buffer[0] and buffer[1]. How can I do it?

    Read the article

  • Convert string to char

    - by Orsol
    Hi. I get from another class string that must be converted to char. It usually contains only one char and that's not a problem. But control chars i receive like '\n' or '\t'. Is there standard methods to convert this to endline or tab char or i need to parse it myself?

    Read the article

  • Changing memory address of a char*

    - by Randall Flagg
    I have the following code: str = "ABCD"; //0x001135F8 newStr = "EFGH"; //0x008F5740 *str after realloc at 5th position - //0x001135FC I want it to point to: 0x008F5740 void str_cat(char** str, char* newStr) { int i; realloc(*str, strlen(*str) + strlen(newStr) + 1); //*str is now 9 length long // I want to change the memory reference value of the 5th char in *str to point to newStr. // Is this possible? // &((*str) + strlen(*str)) = (char*)&newStr; //This is my problem (I think) }

    Read the article

  • C++ vector of char array

    - by Stuart
    I am trying to write a program that has a vector of char arrays and am have some problems. char test [] = { 'a', 'b', 'c', 'd', 'e' }; vector<char[]> v; v.push_back(test); Sorry this has to be a char array because I need to be able to generate lists of chars as I am trying to get an output something like. a a a b a c a d a e b a b c Can anyone point me in the right direction? Thanks

    Read the article

  • Assign bitset member to char

    - by RedX
    I have some code here that uses bitsets to store many 1 bit values into a char. Basically struct BITS_8 { char _1:1; (...) char _8:1; } Now i was trying to pass one of these bits as a parameter into a function void func(char bit){ if(bit){ // do something }else{ // do something else } // and the call was struct BITS_8 bits; // all bits were set to 0 before bits._7 = 1; bits._8 = 1; func(bits._8); The solution was to single the bit out when calling the function: func(bits._8 & 0x128); But i kept going into //do something because other bits were set. I was wondering if this is the correct behaviour or if my compiler is broken. The compiler is an embedded compiler that produces code for freescale ASICs.

    Read the article

  • C++ Template const char array to int

    - by Levi Schuck
    So, I'm wishing to be able to have a static const compile time struct that holds some value based on a string by using templates. I only desire up to four characters. I know that the type of 'abcd' is int, and so is 'ab','abc', and although 'a' is of type char, it works out for a template<int v> struct What I wish to do is take sizes of 2,3,4,5 of some const char, "abcd" and have the same functionality as if they used 'abcd'. Note that I do not mean 1,2,3, or 4 because I expect the null terminator. cout << typeid("abcd").name() << endl; tells me that the type for this hard coded string is char const [5], which includes the null terminator on the end. I understand that I will need to twiddle the values as characters, so they are represented as an integer. I cannot use constexpr since VS10 does not support it (VS11 doesn't either..) So, for example with somewhere this template defined, and later the last line template <int v> struct something { static const int value = v; }; //Eventually in some method cout << typeid(something<'abcd'>::value).name() << endl; works just fine. I've tried template<char v[5]> struct something2 { static const int value = v[0]; } template<char const v[5]> struct something2 { static const int value = v[0]; } template<const char v[5]> struct something2 { static const int value = v[0]; } All of them build individually, though when I throw in my test, cout << typeid(something2<"abcd">::value).name() << endl; I get 'something2' : invalid expression as a template argument for 'v' 'something2' : use of class template requires template argument list Is this not feasible or am I misunderstanding something?

    Read the article

  • char array split ip with strtok

    - by user1480139
    I'm trying to split a IP address like 127.0.0.1 from a file: using following C code: pch2 = strtok (ip,"."); printf("\npart 1 ip: %s",pch2); pch2 = strtok (NULL,"."); printf("\npart 2 ip: %s",pch2); And IP is a char ip[500], that containt an ip. When printing it prints 127 as part 1 but as part 2 it prints NULL? Can someone help me? EDIT: Whole function: FILE *file = fopen ("host.txt", "r"); char * pch; char * pch2; char ip[BUFFSIZE]; IPPart result; if (file != NULL) { char line [BUFFSIZE]; while(fgets(line,sizeof line,file) != NULL) { if(line[0] != '#') { //fputs(line,stdout); pch = strtok (line," "); printf ("%s\n",pch); strncpy(ip, pch, sizeof(pch)-1); ip[sizeof(pch)-1] = '\0'; //pch = strtok (line, " "); pch = strtok (NULL," "); printf("%s",pch); pch2 = strtok (ip,"."); printf("\nDeel 1 ip: %s",pch2); pch2 = strtok (NULL,"."); printf("\nDeel 2 ip: %s",pch2); //if(strcmp(pch,url) == 0) //{ // result.part1 = //} } } fclose(file); }

    Read the article

  • how to access char*** from dll import in C#

    - by mavrick
    I have a function in win32 dll with signature as: void func1(int a, char*** outData) int a -- input parameter char*** outData -- output parameter - pointer to array of char strings Any idea how to access this in C# using dll import & what should be the signature.

    Read the article

  • c++: at what point should I start using "new char[N]" vs a static buffer "char[Nmax]"

    - by dan
    My question is with regard to C++ Suppose I write a function to return a list of items to the caller. Each item has 2 logical fields: 1) an int ID, and 2) some data whose size may vary, let's say from 4 bytes up to 16Kbytes. So my question is whether to use a data structure like: struct item { int field1; char field2[MAX_LEN]; OR, rather, to allocate field2 from the heap, and require the caller to destroy when he's done: struct item{ int field1; char *field2; // new char[N] -- destroy[] when done! Since the max size of field #2 is large, is makes sense that this would be allocated from the heap, right? So once I know the size N, I call field2 = new char[N], and populate it. Now, is this horribly inefficient? Is it worse in cases where N is always small, i.e. suppose I have 10000 items that have N=4?

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >