Search Results

Search found 6123 results on 245 pages for 'unsigned char'.

Page 13/245 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • realloc - converting int to char

    - by Mike
    I'm converting an array of integers into a char by iterating through the whole array, and then I'm adding the resulting string to ncurses's method new_item. For some reason I'm doing something wrong the way I reallocate memory, thus I get the the first column as: -4 Choice 1 0 Choice 1 4 Choice 2 1 Choice 1 4 Choice 3 - Instead of - 2 Choice 1 4 Choice 4 3 Choice 1 4 Exit 4 Choice 1 - #include <stdio.h> #include <stdlib.h> #include <curses.h> #include <menu.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 char *choices[] = { "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Exit", }; int table[5]={0,1,2,3,4}; int main() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); // right here char *convert = NULL; for(i = 0; i < n_choices; ++i){ convert = (char *) realloc (convert, sizeof(char) * 4); sprintf(convert, "%i", table[i]); my_items[i] = new_item(convert, choices[i]); } my_items[n_choices] = (ITEM *)NULL; my_menu = new_menu((ITEM **)my_items); mvprintw(LINES - 2, 0, "F1 to Exit"); post_menu(my_menu); refresh(); while((c = getch()) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; } } free(convert); unpost_menu(my_menu); free_item(my_items[0]); free_item(my_items[1]); free_item(my_items[2]); free_item(my_items[3]); free_item(my_items[4]); free_menu(my_menu); endwin(); }

    Read the article

  • C++ stringstream, string, and char* conversion confusion

    - by Graphics Noob
    My question can be boiled down to, where does the string returned from stringstream.str().c_str() live in memory, and why can't it be assigned to a const char*? This code example will explain it better than I can #include <string> #include <sstream> #include <iostream> using namespace std; int main() { stringstream ss("this is a string\n"); string str(ss.str()); const char* cstr1 = str.c_str(); const char* cstr2 = ss.str().c_str(); cout << cstr1 // Prints correctly << cstr2; // ERROR, prints out garbage system("PAUSE"); return 0; } The assumption that stringstream.str().c_str() could be assigned to a const char* led to a bug that took me a while to track down. For bonus points, can anyone explain why replacing the cout statement with cout << cstr // Prints correctly << ss.str().c_str() // Prints correctly << cstr2; // Prints correctly (???) prints the strings correctly? I'm compiling in Visual Studio 2008.

    Read the article

  • Problem in printing array of char pointer passing from Python

    - by Yan Cheng CHEOK
    My following C code works quite well, till my Python code trying to pass an array of char pointer to it. The output I obtain is The file_name is python-file Another 3 string is not being printed out. Anything I had missed out? C Code #include <iostream> #include "c_interface.h" int foo(const char* file_name, const char** names) { std::cout << "The file_name is " << file_name << std::endl; while (*names) { std::cout << "The name is " << *names << std::endl; names++; } return 0; } /* int main() { const char *c[] = {"123gh", "456443432", "789", 0}; foo("hello", c); getchar(); } */ Python Code #!c:/Python27/python.exe -u from ctypes import * name0 = "NAME0" name1 = "NAME1" name2 = "NAME2" names = ((c_char_p * 1024) * 4)() names[0].value = name0 names[1].value = name1 names[2].value = name2 names[3].value = 0 libc = CDLL("foo.dll") libc.foo("python-file", names)

    Read the article

  • StreamReader returning another char

    - by Fernando
    I'm trying to read the content of a file with a StreamReader, that receives a FileStream. The file has some spaces inside (char 32) and the StreamReader is reading them as 0 (char 48). The screenshot shows the FileStream buffer and the StreamReader buffer. Both have the value 32, but when I call Read(), it returns 48. Am I missing something here? By the way, the code is running under .NET Compact Framework. The code that reads the data: public void Read() { using (StreamReader reader = new StreamReader(InputStream, Encoding.ASCII)) { foreach (var property in DataObject.EnumerateProperties()) { OffsetInfo offset = property.GetTextOffset(); reader.BaseStream.Position = offset.Start - 1; StringBuilder builder = new StringBuilder(offset.Size); int count = 0; while (reader.Peek() >= 0 && count < offset.Size) { char c = (char)reader.Read(); if ((int)c != 32 && c != '\r' && c != '\n') { builder.Append(c); count++; } else { reader.BaseStream.Position++; } } property.SetValue(DataObject, Convert.ChangeType(builder.ToString(), property.PropertyType, CultureInfo.CurrentCulture), null ); } } }

    Read the article

  • PasswordFiled char[] to String in Java connection MySql?

    - by user1819551
    This is a jFrame to connect to the database and this is in the button connect. My issue is in the passwordField NetBeans make me do a char[], but my .getConnection not let me insert the char[] ERROR: "no suitable method found for getConnection(String,String,char[])". So I will change to String right? So when I change and run the jFrame said access denied. when I start doing the System.out.println(l) " Give me the right answer" Like this: "Alex". But when I do the System.out.println(password) "Give me the Array spaces and not the value" Like this: jdbc:mysql://localhost/home inventory root [C@5be5ab68 <--- Array space . What I doing wrong? try { Class.forName("org.gjt.mm.mysql.Driver"); //Load the driver String host = "jdbc:mysql://"+tServerHost.getText()+"/"+tSchema.getText(); String uName = tUsername.getText(); char[] l = pPassword.getPassword(); System.out.println(l); String password= l.toString(); System.out.println(host+uName+l); con = DriverManager.getConnection(host, uName, password); System.out.println(host+uName+password); } catch (SQLException | ClassNotFoundException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } }

    Read the article

  • warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

    - by pyz
    code: #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <sys/socket.h> int main(int argc, char **argv) { char *ptr, **pptr; struct hostent *hptr; char str[32]; //ptr = argv[1]; ptr = "www.google.com"; if ((hptr = gethostbyname(ptr)) == NULL) { printf("gethostbyname error for host:%s\n", ptr); } printf("official hostname:%s\n", hptr->h_name); for (pptr = hptr->h_aliases; *pptr != NULL; pptr++) printf(" alias:%s\n", *pptr); switch (hptr->h_addrtype) { case AF_INET: case AF_INET6: pptr = hptr->h_addr_list; for (; *pptr != NULL; pptr++) printf(" address:%s\n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str))); break; default: printf("unknown address type\n"); break; } return 0; } compiler output below: zhumatoMacBook:CProjects zhu$ gcc gethostbynamedemo.c gethostbynamedemo.c: In function ‘main’: gethostbynamedemo.c:31: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

    Read the article

  • SQlite: Column format for unix timestamp; Integer types

    - by SF.
    Original problem: What is the right column format for a unix timestamp? The net is full of confusion: some posts claim SQLite has no unsigned types - either whatsoever, or with exception of the 64bit int type (but there are (counter-)examples that invoke UNSIGNED INTEGER). The data types page mentions it only in a bigint example. It also claims there is a 6-byte integer but doesn't give a name for it. Of course standard INTEGER being 4-byte signed signed stores unix timestamps as negative numbers. I've heard that some systems return 64-bit timestamps too. OTOH I'm not too fond of wasting 4 bytes to store 1 extra bit (top bit of timestamp), and even if I have to pick a bigger data format, I'd rather go for the 6-byte one. I've even seen a post that claims SQLite unix timestamp is of type REAL... Complete problem: Could someone please clarify that mess?

    Read the article

  • uniq char that need to replaced without to put the "\"

    - by yael
    I need to know if there is some way to replace any string as @ or * or ? or & without to put the "\" before it example perl -pe 'next if /^#/; s/\@d\&/new_value/ if /param5/' test in this example need to replace the @d& with new_value but I need to put the "\" before @ or & can be other way without to put the "\" because I have random char that can be in the old value THX yael

    Read the article

  • replace a 'space' char in filename with an underscore

    - by user38730
    I have a bunch of files in a directory with 'spaces' in the filename. How do I perform a bulk rename of all filenames with 'spaces' and replace them with an '_' char. Looking at the other solutions, I've tried the following command w/o success: find . -name '* *' -exec rename ' ' '_' {} + find: rename: No such file or directory

    Read the article

  • C++ using cdb_read returns extra characters on some reads

    - by Moe Be
    Hi All, I am using the following function to loop through a couple of open CDB hash tables. Sometimes the value for a given key is returned along with an additional character (specifically a CTRL-P (a DLE character/0x16/0o020)). I have checked the cdb key/value pairs with a couple of different utilities and none of them show any additional characters appended to the values. I get the character if I use cdb_read() or cdb_getdata() (the commented out code below). If I had to guess I would say I am doing something wrong with the buffer I create to get the result from the cdb functions. Any advice or assistance is greatly appreciated. char* HashReducer::getValueFromDb(const string &id, vector <struct cdb *> &myHashFiles) { unsigned char hex_value[BUFSIZ]; size_t hex_len; //construct a real hex (not ascii-hex) value to use for database lookups atoh(id,hex_value,&hex_len); char *value = NULL; vector <struct cdb *>::iterator my_iter = myHashFiles.begin(); vector <struct cdb *>::iterator my_end = myHashFiles.end(); try { //while there are more databases to search and we have not found a match for(; my_iter != my_end && !value ; my_iter++) { //cerr << "\n looking for this MD5:" << id << " hex(" << hex_value << ") \n"; if (cdb_find(*my_iter, hex_value, hex_len)){ //cerr << "\n\nI found the key " << id << " and it is " << cdb_datalen(*my_iter) << " long\n\n"; value = (char *)malloc(cdb_datalen(*my_iter)); cdb_read(*my_iter,value,cdb_datalen(*my_iter),cdb_datapos(*my_iter)); //value = (char *)cdb_getdata(*my_iter); //cerr << "\n\nThe value is:" << value << " len is:" << strlen(value)<< "\n\n"; }; } } catch (...){} return value; }

    Read the article

  • checking last char of string in c

    - by radar75
    If I have two types of strings as: const char *str1 = "This is a string with \"quotes escaped at the end\""; const char *str2 = "This is a \"string\" without quotes at the end"; testFn(str1); testFn(str2); int testFn(char *str) { // test & return 1 if ends on no quote // test & return 0 if ends on quote return; } I would like to test if the string ends with a quote " or not What would be a good way of testing this? Thanks

    Read the article

  • Need to skip newline char (\n) from input file

    - by igor
    I am reading in a file into an array. It is reading each char, the problem arises in that it also reads a newline in the text file. This is a sudoku board, here is my code for reading in the char: bool loadBoard(Square board[BOARD_SIZE][BOARD_SIZE]) { ifstream ins; if(openFile(ins)){ char c; while(!ins.eof()){ for (int index1 = 0; index1 < BOARD_SIZE; index1++) for (int index2 = 0; index2 < BOARD_SIZE; index2++){ c=ins.get(); if(isdigit(c)){ board[index1][index2].number=(int)(c-'0'); board[index1][index2].permanent=true; } } } return true;} return false; } like i said, it reads the file, displays on screen, just not in correct order when it encounters the \n

    Read the article

  • Errors/warnings passing int/char arrays by reference

    - by Ankur Banerjee
    I'm working on a program where I try to pass parameters by reference. I'm trying to pass a 2D int array and a 1D char array by reference. Function prototype: void foo (int* (&a)[2][2], char* (&b)[4]) Function call: foo (a, b); However, when I compile the code with -ansi and -Wall flags on gcc, I get the following errors: foo.c: At top level: error: expected ‘)’ before ‘&’ token error: expected ‘;’, ‘,’ or ‘)’ before ‘char’ foo.c: In function ‘main’: error: too many arguments to function ‘foo’ I've stripped out the rest of the code of my program and concentrated on the bits which throw up the errors. I've searched around on StackOverflow and tried out different ways to pass the parameters, but none of them seem to work. (I took this way of passing parameters from the discussion on StackOverflow here.) Could you please tell me where I'm going wrong?

    Read the article

  • SQL Server Concatenate string column value to 5 char long

    - by mrp
    Scenario: I have a table1(col1 char(5)); A value in table1 may '001' or '01' or '1'. Requirement: Whatever value in col1, I need to retrive it in 5 char length concatenate with leading '0' to make it 5 char long. Technique I applied: select right(('00000' + col1),5) from table1; I didn't see any reason, why it doesn't work? but it didn't. Can anyone help me, how I can achieve the desired result?

    Read the article

  • SQL Server Concatinate string column value to 5 char long

    - by mrp
    Scenario: I have a table1(col1 char(5)); A value in table1 may '001' or '01' or '1'. Requirement: Whatever value in col1, I need to retrive it in 5 char length concatenate with leading '0' to make it 5 char long. Technique I applied: select right(('00000' + col1),5) from table1; I didn't see any reason, why it doesn't work? but it didn't. Can anyone help me, how I can achieve the desired result?

    Read the article

  • Need help for this syntax: "#define LEDs (char *) 0x0003010"

    - by Noge
    I'm doing programming of a softcore processor, Nios II from Altera, below is the code in one of the tutorial, I manage to get the code working by testing it on the hardware (DE2 board), however, I could not understand the code. #define Switches (volatile char *) 0x0003000 #define LEDs (char *) 0x0003010 void main() { while (1) *LEDs = *Switches; } What I know about #define is that, it is either used to define a constant, or a macro, but why in the above code, there are casting like, (char *) 0x0003010, in #define? why the 2 constants, Switches and LEDs act like a variable instead of a constant? Thanks in advance !

    Read the article

  • Why do C++ streams use char instead of unsigned char?

    - by Johannes Schaub - litb
    I've always wondered why the C++ Standard library has instantiated basic_[io]stream and all its variants using the char type instead of the unsigned char type. char means (depending on whether it is signed or not) you can have overflow and underflow for operations like get(), which will lead to implementation-defined value of the variables involved. Another example is when you want to output a byte, unformatted, to an ostream using its put function. Any ideas? Note: I'm still not really convinced. So if you know the definitive answer, you can still post it indeed.

    Read the article

  • C++'s char * by swig got problem in Python 3.0

    - by gpliu3
    Our C++ lib works fine with Python2.4 using Swig, returning a C++ char* back to a python str. But this solution hit problem in Python3.0, error is: Exception=(, UnicodeDecodeError('utf8', b"\xb6\x9d\xa.....",0, 1, 'unexpected code byte') Our definition is like(working fine in Python 2.4): void cGetPubModulus( void* pSslRsa, char* cMod, int* nLen ); %include "cstring.i" %cstring_output_withsize( char* cMod, int* nLen ); Suspect swig is doing a Bytes-Str conversion automatically. In python2.4 it can be implicit but in Python3.0 it's no long allowed.. Anyone got a good idea? thanks

    Read the article

  • stack dump accessing malloc char array

    - by robUK
    Hello, gcc 4.4.3 c89 I have the following source code. And getting a stack dump on the printf. char **devices; devices = malloc(10 * sizeof(char*)); strcpy(devices[0], "smxxxx1"); printf("[ %s ]\n", devices[0]); /* Stack dump trying to print */ I am thinking that this should create an char array like this. devices[0] devices[1] devices[2] devices[4] etc And each element I can store my strings. Many thanks for any suggestions,

    Read the article

  • Allocating memory for a array to char pointer

    - by nunos
    The following piece of code gives a segmentation fault when allocating memory for the last arg. What am I doing wrong? Thanks. int n_args = 0, i = 0; while (line[i] != '\0') { if (isspace(line[i++])) n_args++; } for (i = 0; i < n_args; i++) command = malloc (n_args * sizeof(char*)); char* arg = NULL; arg = strtok(line, " \n"); while (arg != NULL) { arg = strtok(NULL, " \n"); command[i] = malloc ( (strlen(arg)+1) * sizeof(char) ); strcpy(command[i], arg); i++; } Thanks.

    Read the article

  • Feed char array into stdin

    - by Brian Lindsey
    I am writing a parser for a mini scripting language. Some of my grammar rules require jumping to a different location in the file to obtain information. There doesn't seem to be a straightforward way to accomplish this. So, I was thinking about loading my data files into a char array array and parsing line by line. This will allow me to jump all over the array with ease. My question is, is it possible to feed char arrays (i.e. char *) into stdin, so I can easily invoke the yyparse() function as needed.

    Read the article

  • C++ putting a 2d array of floats into a char*

    - by sam
    Hello, I'm trying to take a 2d vector of floats (input) and put them into a char* (output) in c++. void foo(const std::vector<std::vector<float> > &input, char* &output ) { char charBuf[sizeof(output)]; int counter = 0; for(unsigned int i=0; i<input.size(); i++) { for(unsigned int p=0; p<input.at(i).size(); p++) { //what the heck goes here } }

    Read the article

  • How to initialize static const char array for ASCII codes [C++]

    - by Janney
    I want to initialize a static const char array with ASCII codes in a constructor, here's my code: class Card { public: Suit(void) { static const char *Suit[4] = {0x03, 0x04, 0x05, 0x06}; // here's the problem static const string *Rank[ 13 ] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'}; // and here. } However i got a whole lot of errors stating that 'initializing' : cannot convert from 'char' to 'const std::string *' 'initializing' : cannot convert from 'int' to 'const std::string *' please help me! Thank you so much.

    Read the article

  • Problem in Building mplsh-run in lshkit

    - by Yijinsei
    Hi guy, been trying out this for quite some time but I'm still unable to built mplsh-run from lshkit Not sure if this would help to explain my situation during the building process /tmp/cc17kth4.o: In function `lshkit::MultiProbeLshRecallTable::reset(lshkit::MultiProbeLshModel, unsigned int, double, double)': mplsh-run.cpp:(.text._ZN6lshkit24MultiProbeLshRecallTable5resetENS_18MultiProbeLshModelEjdd[lshkit::MultiProbeLshRecallTable::reset(lshkit::MultiProbeLshModel, unsigned int, double, double)]+0x230): undefined reference to `lshkit::MultiProbeLshModel::recall(double) const' /tmp/cc17kth4.o: In function `void lshkit::MultiProbeLshIndex<unsigned int>::query_recall<lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> > >(float const*, float, lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> >&) const': mplsh-run.cpp:(.text._ZNK6lshkit18MultiProbeLshIndexIjE12query_recallINS_11TopkScannerINS_6MatrixIfE8AccessorENS_6metric5l2sqrIfEEEEEEvPKffRT_[void lshkit::MultiProbeLshIndex<unsigned int>::query_recall<lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> > >(float const*, float, lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> >&) const]+0x2c4): undefined reference to `lshkit::MultiProbeLsh::genProbeSequence(float const*, std::vector<unsigned int, std::allocator<unsigned int> >&, unsigned int) const' /tmp/cc17kth4.o: In function `void lshkit::MultiProbeLshIndex<unsigned int>::query<lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> > >(float const*, unsigned int, lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> >&)': mplsh-run.cpp:(.text._ZN6lshkit18MultiProbeLshIndexIjE5queryINS_11TopkScannerINS_6MatrixIfE8AccessorENS_6metric5l2sqrIfEEEEEEvPKfjRT_[void lshkit::MultiProbeLshIndex<unsigned int>::query<lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> > >(float const*, unsigned int, lshkit::TopkScanner<lshkit::Matrix<float>::Accessor, lshkit::metric::l2sqr<float> >&)]+0x4a): undefined reference to `lshkit::MultiProbeLsh::genProbeSequence(float const*, std::vector<unsigned int, std::allocator<unsigned int> >&, unsigned int) const' collect2: ld returned 1 exit status the command that i used to built mplsh-run is g++ -I./lshkit/include -L/usr/lib -lm -lgsl -lgslcblas -lboost_program_options-mt mplsh-run.cpp Do you guys have any clue on how I could solve this?

    Read the article

  • error in assigning a const character to a usigned char array in C++

    - by mekasperasky
    #include <iostream> #include <fstream> #include <cstring> using namespace std; typedef unsigned long int WORD; /* Should be 32-bit = 4 bytes */ #define w 32 /* word size in bits */ #define r 12 /* number of rounds */ #define b 16 /* number of bytes in key */ #define c 4 /* number words in key */ /* c = max(1,ceil(8*b/w)) */ #define t 26 /* size of table S = 2*(r+1) words */ WORD S [t],L[c]; /* expanded key table */ WORD P = 0xb7e15163, Q = 0x9e3779b9; /* magic constants */ /* Rotation operators. x must be unsigned, to get logical right shift*/ #define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1))))) #define ROTR(x,y) (((x)>>(y&(w-1))) | ((x)<<(w-(y&(w-1))))) void RC5_DECRYPT(WORD *ct, WORD *pt) /* 2 WORD input ct/output pt */ { WORD i, B=ct[1], A=ct[0]; for (i=r; i>0; i--) { B = ROTR(B-S [2*i+1],A)^A; A = ROTR(A-S [2*i],B)^B; } pt [1] = B-S [1] ;pt [0] = A-S [0]; } void RC5_SETUP(unsigned char *K) /* secret input key K 0...b-1] */ { WORD i, j, k, u=w/8, A, B, L [c]; /* Initialize L, then S, then mix key into S */ for (i=b-1,L[c-1]=0; i!=-1; i--) L[i/u] = (L[i/u]<<8)+K[ i]; for (S [0]=P,i=1; i<t; i++) S [i] = S [i-1]+Q; for (A=B=i=j=k=0; k<3*t; k++,i=(i+1)%t,j=(j+1)%c) /* 3*t > 3*c */ { A = S[i] = ROTL(S [i]+(A+B),3); B = L[j] = ROTL(L[j]+(A+B),(A+B)); } } void printword(WORD A) { WORD k; for (k=0 ;k<w; k+=8) printf("%02.2lX",(A>>k)&0xFF); } int main() { WORD i, j, k, pt [2], pt2 [2], ct [2] = {0,0}; unsigned char key[b]; ofstream out("cpt.txt"); ifstream in("key.txt"); if(!in) { cout << "Cannot open file.\n"; return 1; } if(!out) { cout << "Cannot open file.\n"; return 1; } key="111111000001111"; RC5_SETUP(key); ct[0]=2185970173; ct[1]=3384368406; for (i=1;i<2;i++) { RC5_DECRYPT(ct,pt2); printf("\n plaintext "); printword(pt [0]); printword(pt[1]); } return 0; } when i run this code i get two warnings and also an error saying that i cant assign a char value to my character array . Why is that ?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >