Search Results

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

Page 107/245 | < Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >

  • How can i store data in C in a tabular format?

    - by aks
    Hi, I want to store data in C in tabular format. I am having difficulty in relating the following. Can someone help? For example: I want to store the follwong entries, then what should be the ideal way of storing in C? IP Address Domain Name 1.) 10.1.1.2 www.yahoo.com 2.) 20.1.1.3 www.google.com Should i use structures? Say for example? struct table { unsigned char ip address; char domain_name[20]; }; If not, please clarify?

    Read the article

  • How do I send telnet option codes?

    - by Matt
    I've written a socket listener in Java that just sends some data to the client. If I connect to the server using telnet, I want the server to send some telnet option codes. Do I just send these like normal messages? Like, if I wanted the client to print "hello", I would do this: PrintWriter out = new PrintWriter(clientSocket.getOutputStream()); out.print("hello"); out.flush(); But when I try to send option codes, the client just prints them. Eg, the IAC char (0xff) just gets printed as a strange y character when I do this: PrintWriter out = new PrintWriter(clientSocket.getOutputStream()); out.print((char)0xff); out.flush();

    Read the article

  • How to sanely read and dump structs to disk when some fields are pointers?

    - by bp
    Hello, I'm writing a FUSE plugin in C. I'm keeping track of data structures in the filesystem through structs like: typedef struct { block_number_t inode; filename_t filename; //char[SOME_SIZE] some_other_field_t other_field; } fs_directory_table_item_t; Obviously, I have to read (write) these structs from (to) disk at some point. I could treat the struct as a sequence of bytes and do something like this: read(disk_fd, directory_table_item, sizeof(fs_directory_table_item_t)); ...except that cannot possibly work as filename is actually a pointer to the char array. I'd really like to avoid having to write code like: read(disk_df, *directory_table_item.inode, sizeof(block_number_t)); read(disk_df, directory_table_item.filename, sizeof(filename_t)); read(disk_df, *directory_table_item.other_field, sizeof(some_other_field_t)); ...for each struct in the code, because I'd have to replicate code and changes in no less than three different places (definition, reading, writing). Any DRYer but still maintainable ideas?

    Read the article

  • Struct sockaddr, sin_family is not a member

    - by leon22
    According to this article from msdn ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx) the struct varies depending on which protocol is selected! Now I want to use this code from http://www.intelliproject.net/articles/showArticle/index/check_tcp_udp_port to check if a port is open or not! Now I have the struct sockaddr as follows: struct sockaddr { ushort sa_family; char sa_data[14]; }; but need this strcuture: struct sockaddr { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; Which changes are necessary? (Ws2_32.lib is linked and following includes #define WIN32_LEAN_AND_MEAN // sockets #include "windows.h" #include <winsock2.h> #include <ws2tcpip.h> Thx

    Read the article

  • How return a std::string from C's "getcwd" function

    - by rubenvb
    Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { char* a_cwd = getcwd(NULL,0); string s_cwd(a_cwd); free(a_cwd); return s_cwd; } UPDATE2: without Boost or Qt, the most common stuff can get long-winded (see accepted answer)

    Read the article

  • How to free memory in try-catch blocks?

    - by Kra
    Hi, I have a simple question hopefully - how does one free memory which was allocated in the try block when the exception occurs? Consider the following code: try { char *heap = new char [50]; //let exception occur here delete[] heap; } catch (...) { cout << "Error, leaving function now"; //delete[] heap; doesn't work of course, heap is unknown to compiler return 1; } How can I free memory after the heap was allocated and exception occurred before calling delete[] heap? Is there a rule not to allocate memory on heap in these try .. catch blocks? Thanks

    Read the article

  • rewrite a function using only pointer increment/decrement

    - by Richard Nguyen
    can anyone help me rewrite the function i wrote below using only points and pointer increment/decrement? I dont have much experience with pointer so I dont know what to do. void reverse(char * s) { int i, l = strlen(s); char c; for(i = 0; i < (l >> 1); i++) { c = s[i]; s[i] = s[l - i - 1]; s[l - i - 1] = c; } } do not use pointer arithmetic or array notation. any help or hint on how to rewrite the function above is appriciated. Thanks!

    Read the article

  • While making an RSS reader which saves articles, how can I prevent duplicates?

    - by Koning Baard
    Lets say I have a RSS feed which lists the 3 newest questions on SO. At 1 o'clock, the feed looks like this: While making an RSS reader which saves articles, how can I prevent duplicates? Convert char array to UNICODE in MFC C++ How to deploy a Java Swing application with an embedded JavaDB database? At 2 o'clock, this feed looks like: django url from another template than the one associated with the view-function While making an RSS reader which saves articles, how can I prevent duplicates? Convert char array to UNICODE in MFC C++ (duplicate articles are bold) I want to download the RSS feed every 5 minutes, parse it and save the articles that aren't already saved, but I do not want duplicates (items that remain in the new, updated feed like the examples above). What can I use to determine if an article is already saved? Thanks

    Read the article

  • Console class in java Exception in reading password

    - by satheesh
    Hi, i am trying to use Console class in java. with this code import java.io.Console; public class ConsoleClass { public static void main(String[] args){ Console c=System.console(); char[] pw; pw=c.readPassword("%s","pw :"); for(char ch:pw){ c.format("%c",ch); } c.format("\n"); MyUtility mu =new MyUtility(); while(true){ String name=c.readLine("%s", "input?: "); c.format("output: %s \n",mu.doStuff(name)); } } } class MyUtility{ String doStuff(String arg1){ return "result is " +arg1; } } here i am getting NullPointerException when i tried to run in netbeans but i am not getting any Exception when tried to run in cmd with out netbeans IDE.Why?

    Read the article

  • inline and member initializers

    - by Alexander
    When should I inline a member function and when should I use member initializers? My code is below.. I would like to modify it so I could make use some inline when appropriate and member initializers: #include "Books.h" Book::Book(){ nm = (char*)""; thck = 0; wght = 0; } Book::Book(const char *name, int thickness, int weight){ nm = strdup(name); thck = thickness; wght = weight; } Book::~Book(){ } const char* Book::name(){ return nm; } int Book::thickness(){ return thck; } int Book::weight(){ return wght; } // // Prints information about the book using this format: // "%s (%d mm, %d dg)\n" // void Book::print(){ printf("%s (%d mm, %d dg)\n", nm, thck, wght); } Bookcase::Bookcase(int id){ my_id = id; no_shelf = 0; } int Bookcase::id(){ return my_id; } Bookcase::~Bookcase(){ for (int i = 0; i < no_shelf; i++) delete my_shelf[i]; } bool Bookcase::addShelf(int width, int capacity){ if(no_shelf == 10) return false; else{ my_shelf[no_shelf] = new Shelf(width, capacity); no_shelf++; return true; } } bool Bookcase::add(Book *bp){ int index = -1; int temp_space = -1; for (int i = 0; i < no_shelf; i++){ if (bp->weight() + my_shelf[i]->curCapacity() <= my_shelf[i]->capacity()){ if (bp->thickness() + my_shelf[i]->curWidth() <= my_shelf[i]->width() && temp_space < (my_shelf[i]->width() - my_shelf[i]->curWidth())){ temp_space = (my_shelf[i]->width()- my_shelf[i]->curWidth()); index = i; } } } if (index != -1){ my_shelf[index]->add(bp); return true; }else return false; } void Bookcase::print(){ printf("Bookcase #%d\n", my_id); for (int i = 0; i < no_shelf; i++){ printf("--- Shelf (%d mm, %d dg) ---\n", my_shelf[i]->width(), my_shelf[i]->capacity()); my_shelf[i]->print(); } }

    Read the article

  • passing string literal to std::map::find(..)

    - by ra170
    I've got a std::map. I'm passing string literal to find method. Obviously, I can pass a string literal such as .find("blah"); However, I wanted to declare it upfront, instead of hardcoding the string, so I have couple of choices now: const std::string mystring = "blah"; const char mystring[] = "blah"; static const char * mystring = "blah"; They all work. (or at least compile). My question is, which one should I use? what's the advantage/distavantage over of the other?

    Read the article

  • some logical error in taking up character in java

    - by Himanshu Aggarwal
    This is my code... class info{ public static void main (String[]args) throws IOException{ char gen; while(true) { //problem occurs with this while System.out.print("\nENTER YOUR GENDER (M/F) : "); gen=(char)System.in.read(); if(gen=='M' || gen=='F' || gen=='m' || gen=='f'){ break; } } System.out.println("\nGENDER = "+gen); } } This is my output... ENTER YOUR GENDER (M/F) : h ENTER YOUR GENDER (M/F) : ENTER YOUR GENDER (M/F) : ENTER YOUR GENDER (M/F) : m GENDER = m Could someone please help me understand why it is asking for the gender so many times.

    Read the article

  • help me with xor encryption in c#

    - by x86shadow
    I wrote this code in c# to encrypt a text with a key : using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace ENCRYPT { class XORENC { private static int Bin2Dec(string num) { int _num = 0; for (int i = 0; i < num.Length; i++) { _num += (int)Math.Pow(2, num.Length - i - 1) * int.Parse(num[i].ToString()); } return _num; } private static string Dec2Bin(int num) { if (num < 2) return num.ToString(); return Dec2Bin(num / 2) + (num % 2).ToString(); } public static string StrXor(string str, string key) { string _str = ""; string _key = ""; string _dec = ""; string _temp = ""; for (int i = 0; i < str.Length; i++) { _temp = Dec2Bin(str[i]); for (int j = 0; j < 8 - _temp.Length + 1; j++) { _temp = '0' + _temp; } _str += _temp; } for (int i = 0; i < key.Length; i++) { _temp = Dec2Bin(key[i]); for (int j = 0; j < 8 - _temp.Length + 1; j++) { _temp = '0' + _temp; } _key += _temp; } while (_key.Length < _str.Length) { _key += _key; } if (_key.Length > _str.Length) _key = _key.Substring(0, _str.Length); for (int i = 0; i < _str.Length; i++) { if (_str[i] == _key[i]) { _dec += '0'; } else { _dec += '1'; } } _str = ""; for (int i = 0; i < _dec.Length; i = i + 8) { char _chr = (char)0; _chr = (char)Bin2Dec(_dec.Substring(i, 8)); _str += _chr; } return _str; } } } the problem is that I always get error when I want to decrypt an encryted text with this code. see the example below for more info : string enc_text = ENCRYPT.XORENC("abc","a"); //enc_text = " ??" string dec_text = ENCRYPT.XORENC(enc_text,"a"); //ERROR any one can help ?

    Read the article

  • C Programming: calling free() on error?

    - by kouei
    Hi all, This a follow up on my previous question. link here. My question is: Let's say I have the following code.. char* buf = (char*) malloc(1024); ... for(; i<20; i++) { if(read(fd, buf, 1024) == -1) { // read off a file and store in buffer perror("read failed"); return 1; } ... } free(buf); what i'm trying to get at is that - what if an error occurs at read()? does that mean my allocated memory never gets freed? If that's the case, how do I handle this? Should I be calling free() as part of error handling? Once again, I apologize for the bad English. ^^; Many thanks, K.

    Read the article

  • How to return a string literal from a function

    - by skydoor
    Hi I am always confused about return a string literal or a string from a function. I was told that there might be memory leak because you don't know when the memory will be deleted? For example, in the code below, how to implement foo() so that make the output of the code is "Hello World"? void foo ( ) // you can add parameters here. { } int main () { char *c; foo ( ); printf ("%s",c); return 0; } Also if the return type of foo() is not void, but you can return char*, what should it be.

    Read the article

  • test cases for testing a strtok-alike function [C++]

    - by Neeraj
    Consider the following class definition: class StrToTokens { StrToTokens(const char* str, const char* delimiters = "\t\r\n"); //constructor string getNextToken(); void reset(); bool empty(); } Can someone list some good testcases to test the above class. A few I could think of are: empty string, empty delimiters, repeated delimiters, consecutive delimiters, string with only delimiters. However, the interviewer expected some more(better ones). Can you help out. Thanks.

    Read the article

  • How to determine the end of an integer array when manipulating with integer pointer?

    - by AKN
    Here is the code: int myInt[] ={ 1, 2, 3, 4, 5 }; int *myIntPtr = &myInt[0]; while( *myIntPtr != NULL ) { cout<<*myIntPtr<<endl; myIntPtr++; } Output: 12345....<junks>.......... For Character array: (Since we have a NULL character at the end, no problem while iterating) char myChar[] ={ 'A', 'B', 'C', 'D', 'E', '\0' }; char *myCharPtr = &myChar[0]; while( *myCharPtr != NULL ) { cout<<*myCharPtr<<endl; myCharPtr++; } Output: ABCDE My question is since we say to add NULL character as end of the strings, we rule out such issues! If in case, it is rule to add 0 to the end of integer array, we could have avoided this problem. What say?

    Read the article

  • Difference between debug and release.

    - by atch
    Why when I'm debugging in debug mode everything in code below works as suppose to but when I switch to release I'm getting strange result? void say_hello(int argc, char* argv[])//In release mode argc has different values from 124353625 to 36369852 <include iostream> { std::cout << "In say_hello()\n"; } int main(int argc, char* argv[]) { say_hello(3,argv);//when instead of literal I enter "argc" everything is ok. return 0; } Thanks for help.

    Read the article

  • C++ : size of int, long, etc...

    - by Jérôme
    I'm looking for detailed informations regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler. But are there any standards ? I'm using Visual Studio 2008 on a 32 bit achitecture. Here is what I get : char : 1 byte short : 2 bytes int : 4 bytes long : 4 bytes float : 4 bytes double : 8 bytes I tried to find, without much success, reliable informations telling the sizes of char, short, int , long, double, float (and other types I don't think of) under different architecture and compiler.

    Read the article

  • How to implement best matching logic in TSQL (SQL Server 2000)

    - by sanjay-kumar1911
    I have two tables X and Y: Table X C1 C2 C3 1 A 13 2 B 16 3 C 8 Table Y C1 C2 C3 C4 1 A 2 N 2 A 8 N 3 A 12 N 4 A 5 N 5 B 7 N 6 B 16 N 7 B 9 N 8 B 5 N 9 C 8 N 10 C 2 N 11 C 8 N 12 C 6 N Records in Table Y can be n number CREATE TABLE X(C1 INT, C2 CHAR(1), C3 INT); CREATE TABLE Y(C1 INT, C2 CHAR(1), C3 INT, C4 CHAR(1)); with following data: INSERT INTO X VALUES (1 'A',13 ); INSERT INTO X VALUES (2 'B',16 ); INSERT INTO X VALUES (3 'C',8 ); INSERT INTO Y VALUES (1,'A', 2,'N'); INSERT INTO Y VALUES (2,'A', 8,'N'); INSERT INTO Y VALUES (3,'A', 12,'N'); INSERT INTO Y VALUES (4,'A', 5,'N'); INSERT INTO Y VALUES (5,'B', 7,'N'); INSERT INTO Y VALUES (6,'B', 16,'N'); INSERT INTO Y VALUES (7,'B', 9,'N'); INSERT INTO Y VALUES (8,'B', 5,'N'); INSERT INTO Y VALUES (9,'C', 8,'N'); INSERT INTO Y VALUES (10,'C', 2,'N'); INSERT INTO Y VALUES (11,'C', 8,'N'); INSERT INTO Y VALUES (12,'C', 6,'N'); EXPECTED RESULT Table Y C1 C2 C3 C4 1 A 2 N 2 A 8 Y 3 A 12 N 4 A 5 Y 5 B 7 N 6 B 16 Y 7 B 9 N 8 B 5 N 9 C 8 Y 10 C 2 N 11 C 8 N 12 C 6 N How do I compare value of column C3 in Table X with all possible matches of column C3 of Table Y and to mark records as matched and unmatched in column C4 of Table Y? Possible matches for A (i.e. value of column C2 in Table X) would be (where R is row number i.e. value of column C1 in Table Y): R1, R2, R3, R4, R1+R2, R1+R3, R1+R4, R2+R3, R2+R4, R3+R4, R4+R5, R1+R2+R3, R1+R2+R4, R2+R3+R4, R1+R2+R3+R4

    Read the article

  • Why freed struct in C still has data?

    - by kliketa
    When I run this code: #include <stdio.h> typedef struct _Food { char name [128]; } Food; int main (int argc, char **argv) { Food *food; food = (Food*) malloc (sizeof (Food)); snprintf (food->name, 128, "%s", "Corn"); free (food); printf ("%d\n", sizeof *food); printf ("%s\n", food->name); } I still get 128 Corn although I have freed food. Why is this? Is memory really freed?

    Read the article

  • Legality Of Re-Implementing An Existing API (e.g. GNU implementing the UNIX APIs)

    - by splicer
    I've often wondered about this. I'm not looking for legal advice, just casual opinions ;) If some company publishes an API on the web for their closed-source library, would it be legal for another party to release an open-source implementation of that API? Are function declarations considered source code? Take GNU implementing the UNIX APIs, for example. The UNIX standard gives the following function declaration and defines its required behaviour in English: char * mktemp(char *template); Now, consider an API that lists and declares and describes several thousand (more much complex) functions, enums, etc.; an API which defines a solution to a non-trival set of problems. If an open-source project publishes C headers that copy (verbatim) the function definitions contained in the closed-source company's published API, doesn't that violate some sort copyright law?

    Read the article

  • setsockopt (sys/socket.h)

    - by lojin
    The prototype for setsockopt is: int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len); Are the following all correct ? Which are not ? a.) int buffsize = 50000; setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&buffsize, sizeof(buffsize)); b.) int buffsize = 50000; setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void *)&buffsize, sizeof(buffsize)); c.) char *buffsize = "50000"; setsockopt(s, SOL_SOCKET, SO_RCVBUF, buffsize, strlen(buffsize)); d.) setsockopt(s, SOL_SOCKET, SO_RCVBUF, "50000", 5);

    Read the article

  • some verd problems in qt

    - by prabhakaran
    I am very new to qt, So whatever I facing is either errors or problems. Here goes some of them, 1)Just try to install it in VisualStudio, you will got enough for the day. 2)After you installed it as a separate qt(without embedding it inside visual studio).Open a c++ file in qt, = then you won't get any option to compile it. 3)Create a empty qt4 project like below #include<iostream> using namespace std; int main(int a,char * argv[]) { } Then build it, you will get a error like this C:\qt-greenhouse\Trolltech\Code_less_create_more\Trolltech\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:131: undefined reference to `qMain(int, char**)' Can anybody clear any of these problems to me.

    Read the article

  • Unmanaged C++ instantiation question

    - by Jim Jones
    Want to verify that my understanding of how this works. Have an unmanaged C++ Class with one public instance variable: char* character_encoding; and whose only constructor is defined as: TF_StringList(const char* encoding = "cp_1252"); when I use this class in either managed or unmanaged C++, the first thing I do is declare a pointer to an object of this class: const TF_StringList * categories; Then later I instantiate it: categories = new TF_StringList(); this gives me a pointer to an object of type TF_StringList whose variable character_encoding is set to "cp_1252"; So, is all that logic valid? Jim

    Read the article

< Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >