Search Results

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

Page 145/245 | < Previous Page | 141 142 143 144 145 146 147 148 149 150 151 152  | Next Page >

  • Python and C++ Sockets converting packet data

    - by yeus
    First of all, to clarify my goal: There exist two programs written in C in our laboratory. I am working on a Proxy Server (bidirectional) for them (which will also mainpulate the data). And I want to write that proxy server in Python. It is important to know that I know close to nothing about these two programs, I only know the definition file of the packets. Now: assuming a packet definition in one of the C++ programs reads like this: unsigned char Packet[0x32]; // Packet[Length] int z=0; Packet[0]=0x00; // Spare Packet[1]=0x32; // Length Packet[2]=0x01; // Source Packet[3]=0x02; // Destination Packet[4]=0x01; // ID Packet[5]=0x00; // Spare for(z=0;z<=24;z+=8) { Packet[9-z/8]=((int)(720000+armcontrolpacket->dof0_rot*1000)/(int)pow((double)2,(double)z)); Packet[13-z/8]=((int)(720000+armcontrolpacket->dof0_speed*1000)/(int)pow((double)2,(double)z)); Packet[17-z/8]=((int)(720000+armcontrolpacket->dof1_rot*1000)/(int)pow((double)2,(double)z)); Packet[21-z/8]=((int)(720000+armcontrolpacket->dof1_speed*1000)/(int)pow((double)2,(double)z)); Packet[25-z/8]=((int)(720000+armcontrolpacket->dof2_rot*1000)/(int)pow((double)2,(double)z)); Packet[29-z/8]=((int)(720000+armcontrolpacket->dof2_speed*1000)/(int)pow((double)2,(double)z)); Packet[33-z/8]=((int)(720000+armcontrolpacket->dof3_rot*1000)/(int)pow((double)2,(double)z)); Packet[37-z/8]=((int)(720000+armcontrolpacket->dof3_speed*1000)/(int)pow((double)2,(double)z)); Packet[41-z/8]=((int)(720000+armcontrolpacket->dof4_rot*1000)/(int)pow((double)2,(double)z)); Packet[45-z/8]=((int)(720000+armcontrolpacket->dof4_speed*1000)/(int)pow((double)2,(double)z)); Packet[49-z/8]=((int)armcontrolpacket->timestamp/(int)pow(2.0,(double)z)); } if(SendPacket(sock,(char*)&Packet,sizeof(Packet))) return 1; return 0; What would be the easiest way to receive that data, convert it into a readable python format, manipulate them and send them forward to the receiver?

    Read the article

  • Regular Expression - Match only 7 chars?

    - by Simon
    I'm trying to match a SEDOL (exactly 7 chars: 6 alpha-numeric chars followed by 1 numeric char) My regex ([A-Z 0-9]{6})[0-9]{1} matches correctly but strings greater than 7 chars that begin with a valid match also match (if you see what I mean :)). For example: B3KMJP4 matches correctly but so does: B3KMJP4x which shouldn't match. Can anyone show me how to avoid this?

    Read the article

  • ReadFile doesn't work asynchronously on Win7 and Win2k8

    - by f0b0s
    According to MSDN ReadFile can read data 2 different ways: synchronously and asynchronously. I need the second one. The folowing code demonstrates usage with OVERLAPPED struct: #include <windows.h> #include <stdio.h> #include <time.h> void Read() { HANDLE hFile = CreateFileA("c:\\1.avi", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { printf("Failed to open the file\n"); return; } int dataSize = 256 * 1024 * 1024; char* data = (char*)malloc(dataSize); memset(data, 0xFF, dataSize); OVERLAPPED overlapped; memset(&overlapped, 0, sizeof(overlapped)); printf("reading: %d\n", time(NULL)); BOOL result = ReadFile(hFile, data, dataSize, NULL, &overlapped); printf("sent: %d\n", time(NULL)); DWORD bytesRead; result = GetOverlappedResult(hFile, &overlapped, &bytesRead, TRUE); // wait until completion - returns immediately printf("done: %d\n", time(NULL)); CloseHandle(hFile); } int main() { Read(); } On Windows XP output is: reading: 1296651896 sent: 1296651896 done: 1296651899 It means that ReadFile didn't block and returned imediatly at the same second, whereas reading process continued for 3 seconds. It is normal async reading. But on windows 7 and windows 2008 I get following results: reading: 1296661205 sent: 1296661209 done: 1296661209. It is a behavior of sync reading. MSDN says that async ReadFile sometimes can behave as sync (when the file is compressed or encrypted for example). But the return value in this situation should be TRUE and GetLastError() == NO_ERROR. On Windows 7 I get FALSE and GetLastError() == ERROR_IO_PENDING. So WinApi tells me that it is an async call, but when I look at the test I see that it is not! I'm not the only one who found this "bug": read the comment on ReadFile MSDN page. So what's the solution? Does anybody know? It is been 14 months after Denis found this strange behavior.

    Read the article

  • html:checkbox query

    - by sarah
    Hi All, i have the following code . and in Form is have property called isActive of type char ,how would i get the checked value of it ,i am getting some symbols like 'o' if checked. I am using userform.getIsActive() ,where i am going wrong .I want 'y' or 'n' values

    Read the article

  • HttpWebResponse get mixed up when used inside multiple threads

    - by Holli
    In my Application I have a few threads who will get data from a web service. Basically I just open an URL and get an XML output. I have a few threads who do this continuously but with different URLs. Sometimes the results are mixed up. The XML output doesn't belong to the URL of a thread but to the URL of another thread. In each thread I create an instance of the class GetWebPage and call the method Get from this instance. The method is very simple and based mostly on code from the MSDN documentation. (See below. I removed my error handling here!) public string Get(string userAgent, string url, string user, string pass, int timeout, int readwriteTimeout, WebHeaderCollection whc) { string buffer = string.Empty; HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url); if (!string.IsNullOrEmpty(userAgent)) myWebRequest.UserAgent = userAgent; myWebRequest.Timeout = timeout; myWebRequest.ReadWriteTimeout = readwriteTimeout; myWebRequest.Credentials = new NetworkCredential(user, pass); string[] headers = whc.AllKeys; foreach (string s in headers) { myWebRequest.Headers.Add(s, whc.Get(s)); } using (HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse()) { using (Stream ReceiveStream = myWebResponse.GetResponseStream()) { Encoding encode = Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(ReceiveStream, encode); // Read 1024 characters at a time. Char[] read = new Char[1024]; int count = readStream.Read(read, 0, 1024); int break_counter = 0; while (count > 0 && break_counter < 10000) { String str = new String(read, 0, count); buffer += str; count = readStream.Read(read, 0, 1024); break_counter++; } } } return buffer; As you can see I have no public properties or any other shared resources. At least I don't see any. The url is the service I call in the internet and buffer is the XML Output from the server. Like I said I have multiple instances of this class/method in a few threads (10 to 12) and sometimes buffer does not belong the the url of the same thread but another thread.

    Read the article

  • Parameter has no walue

    - by Simon
    string queryString = "SELECT SUM(skupaj_kalorij)as Skupaj_Kalorij " + "FROM (obroki_save LEFT JOIN users ON obroki_save.ID_uporabnika=users.ID)" + "WHERE users.ID= " + a.ToString() + " AND obroki_save.datum =?"; using (OleDbCommand cmd = new OleDbCommand(queryString,database)) { cmd.Parameters.Add("@datum", OleDbType.Char).Value = DateTime.Now.ToShortDateString(); } Why doesn't the parametr datum get the date value? (the value of at least one complex parameter has not been determined )

    Read the article

  • How to Take whitespace in Input in C

    - by itsaboutcode
    I wanted to take character array from console and it also include white spaces, the only method i know in C is scanf, but it miss stop taking input once it hit with white space. What i should do? Here is what i am doing. char address[100]; scanf("%s", address);

    Read the article

  • Typecast cross-platform compatibility

    - by kaykun
    Hi, what I'm trying to do is append a binary integer into a string object. So far I have this: int number = 5; cppstring.append((char*)&number, 4); It works fine on a x86 system with Windows, but some people are saying its not cross-platform and is unsafe. What is the preferred method to do this?

    Read the article

  • forslash as the default path separator in windows?

    - by Meitham
    Since windows now accept the forslash "/" as a path separator in addition to its default backslash path separator, so that both c:\windows and c:/windows are valid paths (though the later is invalid in cygwin since backslash is escape char) Is there any chance we could set the forslash as the default path separator on windows (GUI), so that the address bar in windows will automatically use it? I heard its possible in a powershell session but anyone knows if it is also possible in a CMD session? Thanks M

    Read the article

  • Compare two Xcode build settings

    - by John Smith
    I have a project where I use two build settings predominantly. Unfortunately today something went wrong. One compiles and the other doesn't. How can I compare the two build settings in XCode to see what the differences are? (For those interested, the error I get in one build is jump to case label crosses initialization of 'const char* selectorName' if you know what this means I'll be very grateful )

    Read the article

  • Cannot work for 2nd iteration because of writing delay.

    - by karikari
    My code's IF-THEN does not work for 2nd iteration. This is due to, the jar processing take some time to write it result inside the output.txt. Since the writing is a bit late, my code's 2nd iteration will always read the previous written value inside the output.txt in order to pass it to the IF-THEN. For example, in 1st iteration: output.txt -- 0.9888 twrite.txt -- msg: ok 2nd iteration: output.txt -- 0.5555 twrite.txt -- msg: ok //the IF-THEN still gives this result which is based on previous iteration. it should be msg: not ok . since it is < 0.7 I need help, how to solve this 'delay' problem? HRESULT CButtonDemoBHO::onDocumentComplete(IDispatch *pDisp, VARIANT *vUrl){ ATLTRACE("CButtonDemoBHO::onDocumentComplete %S\n", vUrl->bstrVal); WinHttpClient client(vUrl->bstrVal); client.SendHttpRequest(); wstring httpResponseHeader = client.GetHttpResponseHeader(); wstring httpResponse = client.GetHttpResponse(); writeToLog(httpResponse.c_str()); if (isMainFrame(pDisp)){ m_normalPageLoad=false; FILE *child = _popen("javaw -jar c:\\simmetrics.jar c:\\chtml.txt c:\\thtml.txt > c:\\output.txt", "r"); fclose(child); char readnumber[10]; float f = 0; FILE *file11 = fopen("c:\\output.txt","r"); char* p = fgets(readnumber,10,file11); std::istringstream iss(p); iss >> f; if (f > 0.7) { wfstream file12 ("c:\\twrite.txt", ios_base::out); file12 << "Msg: ok"; file12.close(); } else { wfstream file12 ("c:\\twrite.txt", ios_base::out); file12 << "Msg: not ok"; file12.close(); } iss.clear(); fclose(file11); return S_OK; } return S_OK; }

    Read the article

  • Exemple where TYPE_ALIGNMENT() fails

    - by JustMaximumPower
    Hi, I have a question relating to alignment in c/c++. In http://stackoverflow.com/questions/364483/determining-the-alignment-of-c-c-structures-in-relation-to-its-members Michael Burr posted this Makro: #define TYPE_ALIGNMENT( t ) offsetof( struct { char x; t test; }, test ) in the comments someone wrote this might fail with non POD typs. Can someone give me an code example where this fails?

    Read the article

  • Extend precision of MySQL's double datatype?

    - by tim82
    I am trying to save the value "6.714285714285714" into a DOUBLE datatype field. Unfortunately it does not fit at all and is cutted by one char. Storing larger numbers becomes less precise. Already searched in the mysql manual and it seems to be that double is the most precise data type available. Anyone knows a practicable workaround? Sorry for my bad english and thx a lot!

    Read the article

  • Internet Explorer 8 + Deflate

    - by Andreas Bonini
    I have a very weird problem.. I really do hope someone has an answer because I wouldn't know where else to ask. I am writing a cgi application in C++ which is executed by Apache and outputs HTML code. I am compressing the HTML output myself - from within my C++ application - since my web host doesn't support mod_deflate for some reason. I tested this with Firefox 2, Firefox 3, Opera 9, Opera 10, Google Chrome, Safari, IE6, IE7, IE8, even wget.. It works with ANYTHING except IE8. IE8 just says "Internet Explorer cannot display the webpage", with no information whatsoever. I know it's because of the compression only because it works if I disable it. Do you know what I'm doing wrong? I use zlib to compress it, and the exact code is: /* Compress it */ int compressed_output_size = content.length() + (content.length() * 0.2) + 16; char *compressed_output = (char *)Alloc(compressed_output_size); int compressed_output_length; Compress(compressed_output, compressed_output_size, (void *)content.c_str(), content.length(), &compressed_output_length); /* Send the compressed header */ cout << "Content-Encoding: deflate\r\n"; cout << boost::format("Content-Length: %d\r\n") % compressed_output_length; cgiHeaderContentType("text/html"); cout.write(compressed_output, compressed_output_length); static void Compress(void *to, size_t to_size, void *from, size_t from_size, int *final_size) { int ret; z_stream stream; stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; if ((ret = deflateInit(&stream, CompressionSpeed)) != Z_OK) COMPRESSION_ERROR("deflateInit() failed: %d", ret); stream.next_out = (Bytef *)to; stream.avail_out = (uInt)to_size; stream.next_in = (Bytef *)from; stream.avail_in = (uInt)from_size; if ((ret = deflate(&stream, Z_NO_FLUSH)) != Z_OK) COMPRESSION_ERROR("deflate() failed: %d", ret); if (stream.avail_in != 0) COMPRESSION_ERROR("stream.avail_in is not 0 (it's %d)", stream.avail_in); if ((ret = deflate(&stream, Z_FINISH)) != Z_STREAM_END) COMPRESSION_ERROR("deflate() failed: %d", ret); if ((ret = deflateEnd(&stream)) != Z_OK) COMPRESSION_ERROR("deflateEnd() failed: %d", ret); if (final_size) *final_size = stream.total_out; return; }

    Read the article

  • wireless profile saving problem please help me out

    - by Jayjitraj
    DATA_BLOB in; DATA_BLOB out; BYTE pin=(BYTE)"FIPL2"; DWORD din=strlen((char*)pin)+1; in.pbData = pin; in.cbData = din; if(CryptProtectData(&in,L"what is it",NULL,NULL,NULL,0,&out)) { BYTE *b=out.pbData; Now I want to convert it into hexadecimal to save as my wifi password so what should i do }

    Read the article

  • Translating C++'s sprintf format string to C#'s string.Format

    - by thebackup
    I found the following C++ code (comments added myself): // frame_name is a char array // prefix is std::string // k is a for loop counter // frames is a std::vector string sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str()); I then try to translate it to C# // prefix is string // k is a for loop counter // frames is List<string> string frameName = string.Format("{0}_(what goes in here?).bmp", prefix, k, frames[k]); Basically, what would be the C# equivalent of the C++ format string "%s_%0*s.bmp"?

    Read the article

  • StringBuffer wont read whole stream into a string (JAVA/Android)

    - by Levara
    Hi all! I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm new to both Java and Android. Problem is: Reader reads whole page source, but in the last while iteration it doesn't append to stringBuffer that last part. Using debbuger I have determined that, in the last loop iteration, string buff is created, but stringBuffer just doesnt append it. I need to parse retrieved content. Is there any better way to handle the content for parsing than using strings. I've read on numerous other sites that string size in Java is limited only by available heap size. I've tried with StringBuilder too. Anyone know what could be the problem. Btw feel free to suggest any improvements to the code. Thanks! URL u; try { u = new URL("http://feeds.timesonline.co.uk/c/32313/f/440134/index.rss"); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestProperty("User-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)"); c.setRequestMethod("GET"); c.setDoOutput(true); c.setReadTimeout(3000); c.connect(); StringBuffer stringBuffer = new StringBuffer(""); InputStream in = c.getInputStream(); InputStreamReader inp = new InputStreamReader(in); BufferedReader reader = new BufferedReader(inp); char[] buffer = new char[3072]; int len1 = 0; while ( (len1 = reader.read(buffer)) != -1 ) { String buff = new String(buffer,0,len1); stringBuffer.append(buff); } String stranica = new String(stringBuffer); c.disconnect(); reader.close(); inp.close(); in.close();

    Read the article

  • Not naming a type - C++

    - by ML
    I am trying to convert an Adobe CS4 based plugin to CS5. This project has never been mine, this is the first time that i am seeing it. When I compile the source with what i was given, I get errors like: Does not name a type Example: SPAPI SPErr SPBasicAcquireSuite( const char *name, int64 version, const void **suite ); I get that: SPErr does not name a type I dont see any classes with SPErr being defined, but I doubt that Adobe has left this out of the SDK. I am using the PS_CS5_SDK_3 SDK

    Read the article

  • C++ preprocessing error in the code

    - by mkal
    #include "iostream" #include "string" using namespace std; #define AA(bb) \ string(::##bb); int main (int argc, char *argv[]) { AA(aa); } This gives me a bunch of errors but I am trying to understand this error pre.cpp:11:1: error: pasting "::" and "aa" does not give a valid preprocessing token Any ideas?

    Read the article

  • what does this error mean in c?

    - by mekasperasky
    #include<stdio.h> #include<ctype.h> int main() { char a,b; FILE *fp; fp=fopen("lext.txt","w"); fprintf(fp,"PLUS"); return 0; } the error i get is this /tmp/ccQyyhxo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

    Read the article

< Previous Page | 141 142 143 144 145 146 147 148 149 150 151 152  | Next Page >