Search Results

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

Page 111/245 | < Previous Page | 107 108 109 110 111 112 113 114 115 116 117 118  | Next Page >

  • How can I obtain the IPv4 address of the client?

    - by Dr Dork
    Hello! I'm prepping for a simple work project and am trying to familiarize myself with the basics of socket programming in a Unix dev environment. At this point, I have some basic server side code setup to listen for incoming TCP connection requests from clients after the parent socket has been created and is set to listen... int sockfd, newfd; unsigned int len; socklen_t sin_size; char msg[]="Test message sent"; char buf[MAXLEN]; int st, rv; struct addrinfo hints, *serverinfo, *p; struct sockaddr_storage client; char ip[INET6_ADDRSTRLEN]; . . //parent socket creation and listen code omitted for simplicity . //wait for connection requests from clients while(1) { //Returns the socketID and address of client connecting to socket if( ( newfd = accept(sockfd, (struct sockaddr *)&client, &len) ) == -1 ){ perror("Accept"); exit(-1); } if( (rv = recv(newfd, buf, MAXLEN-1, 0 )) == -1) { perror("Recv"); exit(-1); } struct sockaddr_in *clientAddr = ( struct sockaddr_in *) get_in_addr((struct sockaddr *)&client); inet_ntop(client.ss_family, clientAddr, ip, sizeof ip); printf("Receive from %s: query type is %s\n", ip, buf); if( ( st = send(newfd, msg, strlen(msg), 0)) == -1 ) { perror("Send"); exit(-1); } //ntohs is used to avoid big-endian and little endian compatibility issues printf("Send %d byte to port %d\n", ntohs(clientAddr->sin_port) ); close(newfd); } } I found the get_in_addr function online and placed it at the top of my code and use it to obtain the IP address of the client connecting... // get sockaddr, IPv4 or IPv6: void *get_in_addr(struct sockaddr *sa) { if (sa->sa_family == AF_INET) { return &(((struct sockaddr_in*)sa)->sin_addr); } return &(((struct sockaddr_in6*)sa)->sin6_addr); } but the function always returns the IPv6 IP address since thats what the sa_family property is set as. My question is, is the IPv4 IP address stored anywhere in the data I'm using and, if so, how can I access it? Thanks so much in advance for all your help!

    Read the article

  • Create a modifiable string literal in C++

    - by Anne
    Is it possible to create a modifiable string literal in C++? For example: char* foo[] = { "foo", "foo" }; char* afoo = foo[0]; afoo[2] = 'g'; // access violation This produces an access violation because the "foo"s are allocated in read only memory (.rdata section I believe). Is there any way to force the "foo"s into writable memory (.data section)? Even via a pragma would be acceptable! (Visual Studio compiler) I know I can do strdup and a number of other things to get around the problem, but I want to know specifically if I can do as I have asked. :)

    Read the article

  • Freeing a character pointer returns error

    - by Kraffs
    I'm trying to free a character pointer after having used it but it returns a strange error. The error says: "_CrtDbgREport: String too long or IO Error" The debugger itself returns no errors while compiling. The code currently looks like this: void RespondToUser(SOCKET client, SOCKET server) { char buffer[80]; char *temp = malloc(_scprintf("HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME)); sprintf(temp, "HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME); send(client, temp, strlen(temp), 0); closesocket(client); free(temp); ListenToUsers(server); } The problem only occurs when I try to free the temp pointer from the memory and not otherwise. What might be causing this?

    Read the article

  • c++ fread changing fgetpos strangely

    - by Steve
    If I run: FILE* pFile = fopen("c:\\08.bin", "r"); fpos_t pos; char buf[5000]; int ret = fread(&buf, 1, 9, pFile); fgetpos(pFile, &pos); I get ret = 9 and pos = 9. However if I run FILE* pFile = fopen("c:\\08.bin", "r"); fpos_t pos; char buf[5000]; int ret = fread(&buf, 1, 10, pFile); fgetpos(pFile, &pos); ret = 10 as expected, but pos = 11! How can this be?

    Read the article

  • reading unicode

    - by user121196
    I'm using java io to retrieve text from a server that might output character such as é. then output it using System.err, they turn out to be '?'. I am using UTF8 encoding. what's wrong? int len=0; char[]buffer=new char[1024]; OutputStream os = sock.getOutputStream(); InputStream is = sock.getInputStream(); os.write(query.getBytes("UTF8"));//iso8859_1")); Reader reader = new InputStreamReader(is, Charset.forName("UTF-8")); do{ len = reader.read(buffer); if (len0) { if(outstring==null)outstring=new StringBuffer(); outstring.append(buffer,0,len); } }while(len0); System.err.println(outstring);

    Read the article

  • Question about C Pointers (just learning)

    - by Mike
    I am curious as to why this is an error and what the error message means. Here is some code. int *x[] = {"foo", "bar", "baz"}; int *y[] = {"foo", "bar", "baz"}; x = y; I try to compile and I get this: error: incompatible types when assigning to type ‘char [3]’ from type ‘char *’ Question #1 why is this an error? and Question #2 why are the types different? Thanks for you help.

    Read the article

  • function in c language

    - by sandy101
    Hello, I am practice the function in c and come across to the program .... include int main() { float a=15.5; char ch ='C'; printit(a,ch); return 0; } printit(a,ch) { printf("%f\n%c",a,ch); } I want to know that why the above program compile and not give the error as i understood so for is ... 1) The function in c must be declared with the specific prototype (but this program does not contain the prototype ) 2)why the program give the output 'x'for the char variable 3)can the function in c are capable of accepting the value without being declared about type in parameters like what has done in the function declaration .... plz.... help

    Read the article

  • Function argument treated as undeclared

    - by Mikulas Dite
    I've prepared this simple example which is not working for me #include <stdio.h> #include <stdlib.h> FILE *fp; char filename[] = "damy.txt"; void echo (char[] text) { fp = fopen(filename, "a"); fwrite(text, 1, strlen(text), fp); fclose(fp); printf(text); } int main () { echo("foo bar"); return 0; } It's supposed to write both to command window and to file. However, this gives compilation error - the text used in echo() is not declared. Does c need another declaration of the variable?

    Read the article

  • Class Members Over Exports

    - by VirusEcks
    When Using DLLs or Code-injecting to be Specific this is an example class only intended for explaining class test { int newint1; char newchararray[512]; void (*newfunction1)( int newarg1 ); int newfunction2( bool newarg1, char newarg2 ) { return newint1; } } mynewclass1; that covers most common elements that's included in classes now when exporting this function to another DLL or application and missed an element of those, either data member or function member, private or public what happens or changed their order ? and if each function is assigned it's value when Code-Injecting like mynewclass1.newfunction1 = (void *)(newexportedfunction); what's the happens in this case, if members of the class are pointers that are assigned after class construction and then missed one member or changed their order ?

    Read the article

  • Scala, make my loop more functional

    - by Pengin
    I'm trying to reduce the extent to which I write Scala (2.8) like Java. Here's a simplification of a problem I came across. Can you suggest improvements on my solutions that are "more functional"? Transform the map val inputMap = mutable.LinkedHashMap(1->'a',2->'a',3->'b',4->'z',5->'c') by discarding any entries with value 'z' and indexing the characters as they are encountered First try var outputMap = new mutable.HashMap[Char,Int]() var counter = 0 for(kvp <- inputMap){ val character = kvp._2 if(character !='z' && !outputMap.contains(character)){ outputMap += (character -> counter) counter += 1 } } Second try (not much better, but uses an immutable map and a 'foreach') var outputMap = new immutable.HashMap[Char,Int]() var counter = 0 inputMap.foreach{ case(number,character) => { if(character !='z' && !outputMap.contains(character)){ outputMap2 += (character -> counter) counter += 1 } } }

    Read the article

  • int[] to string c#

    - by Robin Webdev
    Hi I'm developing an client application in C# and the server is written in c++ the server uses: inline void StrToInts(int *pInts, int Num, const char *pStr) { int Index = 0; while(Num) { char aBuf[4] = {0,0,0,0}; for(int c = 0; c < 4 && pStr[Index]; c++, Index++) aBuf[c] = pStr[Index]; *pInts = ((aBuf[0]+128)<<24)|((aBuf[1]+128)<<16)|((aBuf[2]+128)<<8)|(aBuf[3]+128); pInts++; Num--; } // null terminate pInts[-1] &= 0xffffff00; } to convert an string to int[] in my c# client i recieve: int[4] { -14240, -12938, -16988, -8832 } How do I convert the array back to an string? I don't want to use unsafe code (e.g. pointers) Any of my tries resulted in unreadable strings.

    Read the article

  • strenge exception phenomenon in win7

    - by Level 2
    Hello all, I spot some interesting artcles about exception handle in codeproject http://www.codeproject.com/KB/cpp/seexception.aspx after reading, I decided to do some experiment. The first time I try to excute the following code char *p; p[0] = 0; The program died without question. But After serveral time I execute the same problem binary code. It magically did fine. even the following code is doing well. any clue or explain? char *p p[1000] = 'd'; cout<<p[1000]<<endl; my os is windows 7 64bit and compiler is vs2008 rc1.

    Read the article

  • strcat() won't exit

    - by Tristan Sebens
    I'm trying to implement a very basic server in C, one part of which is constructing HTTP headers. To do this I have written a class called header_builder, which basically constructs the headers for me. One of the most basic methods of this class is append_header_line, shown below: void append_header_line( const char *line, char *hdr ) { printf("Adding header line\n"); strcat( hdr, line ); printf("Line added. Adding ending.\n"); strcat( hdr, "\r\n" ); printf("Success\n"); } All it's supposed to do is tack the "line" parameter onto the end of the "hdr" parameter, and then add "\r\n" to the end of it all. The problem is that the first strcat call never exits. When I run this code, all it does is say: Adding header line Which means that the following lines never execute, and I can't figure out why. Any thoughts?

    Read the article

  • Strange exception phenomenon in Windows 7

    - by Level 2
    I spot some interesting articles about exception handle in CodeProject http://www.codeproject.com/KB/cpp/seexception.aspx After reading, I decided to do some experiment. The first time I try to execute the following code char *p; p[0] = 0; The program died without question. But After several times when I executed the same problem binary code, it magically did fine. Even the following code is doing well. Any clue or explanation? char *p p[1000] = 'd'; cout<<p[1000]<<endl; My O/S is Windows 7 64bit and compiler is VS2008 rc1.

    Read the article

  • Using pipes inside a class in C++

    - by Paul
    I'm trying to use this tutorial to make plots with Gnuplot in C++. However I will be using the pipe to Gnuplot from within a class, but then I run into some problems: I've got a header file where I declare all variables etc. I need to declare the pipe-variable here too, but how do I do that? I've tried doing it straight away, but it doesn't work: Logger.h: class Logger { FILE pipe; } Logger.cpp: Logger::Logger() { //Constructor *pipe = popen("gnuplot -persist","w"); } Gives the error Logger.cpp:28: error: no match for ‘operator=’ in ‘*((Logger*)this)->Logger::pipe = popen(((const char*)"gnuplot -persist"), ((const char*)"w"))’ Suggestions?

    Read the article

  • c++: truth assignment warning with arguments?

    - by John
    I use the following to work with arguments in my programs, but it seems to just hand me a warning (just a warning): "warning: suggest parentheses around assignment used as truth value" The beginning of the code is as follows: enum{OPT_DISP_H = 0x2, OPT_DISP_W = 0x1}; int main(int argc, char *argv[]) { int opt = 0x00; char c; while((++argv)[0] && argv[0][0]=='-'){ while(c =* ++argv[0]) switch(c){ case 'h': opt |= OPT_DISP_H; break; //etc.. The while(c =* ++argv[0]) part being where the warning persists. The code works fine, but what does this warning mean opposed to what is used? I think the code is c = *++argv[0], using the pointer. So why does the single = work and what is really recommended to be used?

    Read the article

  • Casting a Calculated Column in a MySQL view.

    - by Chris Brent
    I have a view that contains a calculated column. Is there are a way to cast it as a CHAR or VARCHAR rather than a VARBINARY ? Obviously, I have tried using CAST(... as CHAR) but it gives an error. Here is a simple replicable example. CREATE VIEW view_example AS SELECT concat_ws('_', lpad(9, 3,'0'), lpad(1,3,'0'), date_format(now(),'%Y%m%d%H%i%S')) AS calculated_field_id; This is how my view is created: describe view_example; +---------------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------------+---------------+------+-----+---------+-------+ | calculated_field_id | varbinary(27) | YES | | NULL | | +---------------------+---------------+------+-----+---------+-------+ select version(); +-----------------------+ | version() | +-----------------------+ | 5.0.51a-community-log | +-----------------------+

    Read the article

  • How do I compare vectors in C++?

    - by Sam Phelps
    I am trying to compare two vector objects, and return a single vector containing all the chars which appear in both vectors. How would I go about this without writing some horribly complex manual method which compares every char in the first vector to every char in the second vector and using an if to add it to a third vector (which would be returned) if they match. Maybe my lack of real experience with vectors is making me imagine this will be harder than it really is, but I suspect there is some simplier way which I have been unable to find through searching.

    Read the article

  • SQL Query taking too long

    - by user345426
    I am trying to optimize the SQL query listed below. It is basically a search engine code that retrieves products based on the products name. It also checks products model number and whether or not it is enabled. This executes in about 1.6 seconds when I run it directly through the phpMyAdmin tool but takes about 3 seconds in total to load in conjunction with the PHP file it is placed in. I need to add a category search functionality and now that is crashing the MySQL server, HELP! SELECT DISTINCT p.products_id , p.products_image , p.products_price , s.specials_new_products_price, p.products_weight , p.products_unit_quantity , pd.products_name , pd.products_img_alt , pd.products_affiliate_url FROM products AS p LEFT JOIN vendors v ON v.vendors_id = p.vendors_id LEFT JOIN specials AS s ON s.products_id = p.products_id AND s.status = 1, categories AS c , products_description AS pd , products_to_categories AS p2c WHERE ( ( pd.products_name LIKE '%cleaning%' AND pd.products_name LIKE '%supplies%' ) OR ( p.products_model LIKE '%cleaning%' AND p.products_model LIKE '%supplies%' ) OR p.products_id = 'cleaning supplies' OR v.vendors_prefix = 'cleaning supplies' OR CONCAT( CAST(v.vendors_prefix AS CHAR), '-', CAST(p.products_id AS CHAR) ) = 'cleaning supplies' ) AND p.products_status = '1' AND c.categories_status = '1' AND p.products_id = pd.products_id AND p2c.products_id = pd.products_id AND p2c.categories_id = c.categories_id ORDER BY pd.products_name

    Read the article

  • strftimedoesnt display year correctly

    - by paultop6
    Hi guys, i have the following code below: const char* timeformat = "%Y-%m-%d %H:%M:%S"; const int timelength = 20; char timecstring[timelength]; strftime(timecstring, timelength, timeformat, currentstruct); cout << "timecstring is: " << timecstring << "\n"; currentstruct is a tm*. The cout is giving me the date in the correct format, but the year is not 2010, but 3910. I know there is something to do with the year cound starting at 1900, but im not sure how to get strftime to recognise this and not add 1900 to the value of 2010 that is there, can anyone help. Regards Paul

    Read the article

  • Removing first two elements of a string array in C

    - by sandeep p
    How can I remove first two elements of a string array? I have a code which is something like this. char *x[10]; .............. .............. .............. char *event[20]; event[0]=strtok(x[i]," "); event[1]=strtok(NULL," "); event[2]=strtok(NULL," "); event[3]=strtok(NULL," "); event[4]=strtok(NULL," "); event[5]=strtok(NULL," "); for(i=2;i<length;i++) { strcpy(event[i-2],event[i]); } I observed that only event[0] has proper values. I printed the contents of event[][] before for loop and it displays correctly. Could you please tell me why this is wrong? and a possible solution?

    Read the article

  • What is wrong with this c strdup code?

    - by bstullkid
    Consider this code: char *strs[] = { "string1", "string2", NULL }; char *ptr1 = NULL, *ptr2 = NULL, *tmp; short iter = 0; tmp = ptr1; while (iter < 2) { tmp = strdup(strs[iter]); tmp = ptr2; iter++; } printf("1: %s\n2: %s\n", ptr1, ptr2); I want this to output "string1\nstring2\n" however str1 and str2 remain null. What am I doing wrong?

    Read the article

  • Solving C++ 'target of assignment not really an lvalue' errors

    - by Jason
    Given this code: void FrMemCopy(void *to, const void *from, size_t sz) { size_t sz8 = sz >> 3; size_t sz1 = sz - (sz8 << 3); while (sz8-- != 0) { *((double *)to)++ = *((double *)from)++; } while (sz1-- != 0) { *((char *)to)++ = *((char *)from)++; } } I am receiving target of assignment not really an lvalue warnings on the 2 lines inside the while loops. Can anyone break down those lines? a cast then an increment? What is a simplier way to write that? What does the error mean?

    Read the article

  • parsing command option with default values and range constrains in C

    - by agramfort
    Hi, I need to parse command line arguments in C. My arguments are basically int or float with default values and range constrains. I've started to implement something that look like this: option_float(float* out, int argc, char* argv, char* name, description, float default_val, int is_optional, float min_value, float max_value) which I call for example with: float* pct; option_float(pct, argc, argv, "pct", "My super percentage option", 50, 1, FALSE, 0, 100) however I don't want to reinvent the wheel ! My objective is to have error checking of range constrains, throw an error when the option is not optional and is not set. And generate the help message usually given by usage() function. The usage text would look like this: --pct My super percentage option (default : 50). Should be in [0, 100] I've started with getopt but it is too limited for what I want to do and I feel it still requires me to write too much code for a simple usecase like this. thanks

    Read the article

  • ASP/HTML problem with spaces and monofonts

    - by nickik
    I have a ASP has a Function that converts ä to &auml so far so good. I have lets say space for 10 char's if there are more cut them of if there are less fill the space up with &nbsp's. . Like this: test &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp but if i say "täst" it does this: te &auml t &nbsp It interprets the &auml not as one char it looks at it as 6 chars. Is there a clever way around that? This problem messes up my design because I need the right count of spaces. The whole thing goes into a big select box. Of you have to add a ; at the end of ever &... I could add them because the Editor would really interprt them.

    Read the article

< Previous Page | 107 108 109 110 111 112 113 114 115 116 117 118  | Next Page >