Search Results

Search found 2136 results on 86 pages for 'dominik str'.

Page 15/86 | < Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • Using a function with reference as a function with pointers?

    - by epatel
    Today I stumbled over a piece of code that looked horrifying to me. The pieces was chattered in different files, I have tried write the gist of it in a simple test case below. The code base is routinely scanned with FlexeLint on a daily basis, but this construct has been laying in the code since 2004. The thing is that a function implemented with a parameter passing using references is called as a function with a parameter passing using pointers...due to a function cast. The construct has worked since 2004 on Irix and now when porting it actually do work on Linux/gcc too. My question now. Is this a construct one can trust? I can understand if compiler constructors implement the reference passing as it was a pointer, but is it reliable? Are there hidden risks? Should I change the fref(..) to use pointers and risk braking anything in the process? What to you think? #include <iostream> using namespace std; // ---------------------------------------- // This will be passed as a reference in fref(..) struct string_struct { char str[256]; }; // ---------------------------------------- // Using pointer here! void fptr(const char *str) { cout << "fptr: " << str << endl; } // ---------------------------------------- // Using reference here! void fref(string_struct &str) { cout << "fref: " << str.str << endl; } // ---------------------------------------- // Cast to f(const char*) and call with pointer void ftest(void (*fin)()) { void (*fcall)(const char*) = (void(*)(const char*))fin; fcall("Hello!"); } // ---------------------------------------- // Let's go for a test int main() { ftest((void (*)())fptr); // test with fptr that's using pointer ftest((void (*)())fref); // test with fref that's using reference return 0; }

    Read the article

  • How can I prevent SerializeJSON from changing Yes/No/True/False strings to boolean?

    - by Dan Roberts
    I have a data struct being stored in JSON format, converted using the serializeJSON function. The problem I am running into is that strings that can be boolean in CF such as Yes,No,True,and False are converted into JSON as boolean values. Below is example code. Any ideas on how to prevent this? Code: <cfset test = {str='Yes'}> <cfset json = serializeJSON(test)> <cfset fromJSON = deserializeJSON(json)> <cfoutput> #test.str#<br> #json#<br> #fromJSON.str# </cfoutput> Result: Yes {"STR":true} YES

    Read the article

  • Fastest way to put contents of Set<String> to a single String with words separated by a whitespace?

    - by Lars Andren
    I have a few Set<String>s and want to transform each of these into a single String where each element of the original Set is separated by a whitespace " ". A naive first approach is doing it like this Set<String> set_1; Set<String> set_2; StringBuilder builder = new StringBuilder(); for (String str : set_1) { builder.append(str).append(" "); } this.string_1 = builder.toString(); builder = new StringBuilder(); for (String str : set_2) { builder.append(str).append(" "); } this.string_2 = builder.toString(); Can anyone think of a faster, prettier or more efficient way to do this?

    Read the article

  • Why can't pass Marshaled interface as integer(or pointer)

    - by cemick
    I passed ref of interface from Visio Add-ins to MyCOMServer (http://stackoverflow.com/questions/2455183/interface-marshalling-in-delphi).I have to pass interface as pointer in internals method of MyCOMServer. I try to pass interface to internal method as pointer of interface, but after back cast when i try call method of interface I get exception. Simple example(Fisrt block execute without error, but At Second block I get Exception after addressed to property of IVApplication interface): procedure TMyCOMServer.test(const Interface_:IDispatch); stdcall; var IMy:_IMyInterface; V: Variant; Str: String; I: integer; Vis: IVApplication; begin ...... Self.QuaryInterface(_IMyInterface,IMy); str := IA.ApplicationName; V := Integer(IMy); i := V; Pointer(IMy) := Pointer(i); str := IMy.SomeProperty; // normal completion str := (Interface_ as IVApplication).Path; V := Interface_; I := V; Pointer(Vis) := Pointer(i); str := Vis.Path; // 'access violation at 0x76358e29: read of address 0xfeeefeee' end; Why I can't do like this?

    Read the article

  • Removing a character from a string

    - by Prasanth Madhavan
    i have a string. I want to delete the last character of the string if it is a space. i tried the following code, str.erase(remove_if(str.begin(), str.end(), isspace), str.end()); but my g++ compiler gives me an error saying: error: no matching function for call to ‘remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)’ please help.

    Read the article

  • Reading POST data from html form sent to serversocket.

    - by user32167
    i try to write simplest possible server app in Java, displaying html form with textarea input, which after submitting gives me possibility to parse xml typed in that textarea. For now i build simple serversocket based server like that: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class WebServer { protected void start() { ServerSocket s; String gets = ""; System.out.println("Start on port 80"); try { // create the main server socket s = new ServerSocket(80); } catch (Exception e) { System.out.println("Error: " + e); return; } System.out.println("Waiting for connection"); for (;;) { try { // wait for a connection Socket remote = s.accept(); // remote is now the connected socket System.out.println("Connection, sending data."); BufferedReader in = new BufferedReader(new InputStreamReader( remote.getInputStream())); PrintWriter out = new PrintWriter(remote.getOutputStream()); String str = "."; while (!str.equals("")) { str = in.readLine(); if (str.contains("GET")){ gets = str; break; } } out.println("HTTP/1.0 200 OK"); out.println("Content-Type: text/html"); out.println(""); // Send the HTML page String method = "get"; out.print("<html><form method="+method+">"); out.print("<textarea name=we></textarea></br>"); out.print("<input type=text name=a><input type=submit></form></html>"); out.println(gets); out.flush(); remote.close(); } catch (Exception e) { System.out.println("Error: " + e); } } } public static void main(String args[]) { WebServer ws = new WebServer(); ws.start(); } } After form (textarea with xml and one additional text input) is submitted in 'gets' String-type variable I have Urlencoded values of my variables (also displayed on the screen, it looks like that: gets = GET /?we=%3Cnetwork+ip_addr%3D%2210.0.0.0%2F8%22+save_ip%3D%22true%22%3E%0D%0A%3Csubnet+interf_used%3D%22200%22+name%3D%22lan1%22+%2F%3E%0D%0A%3Csubnet+interf_used%3D%22254%22+name%3D%22lan2%22+%2F%3E%0D%0A%3C%2Fnetwork%3E&a=fooBar HTTP/1.1 What can i do to change GET to POST method (if i simply change it in form and than put " if (str.contains("POST")){" it gives me string like gets = POST / HTTP/1.1 with no variables. And after that, how i can use xml from my textarea field (called 'we')?

    Read the article

  • What's the fastest way to check if a word from one string is in another string?

    - by Mike Trpcic
    I have a string of words; let's call them bad: bad = "foo bar baz" I can keep this string as a whitespace separated string, or as a list: bad = bad.split(" "); If I have another string, like so: str = "This is my first foo string" What's the fasted way to check if any word from the bad string is within my comparison string, and what's the fastest way to remove said word if it's found? #Find if a word is there bad.split(" ").each do |word| found = str.include?(word) end #Remove the word bad.split(" ").each do |word| str.gsub!(/#{word}/, "") end

    Read the article

  • unicode data with custom font doesn't work properly in ipad

    - by David Ohanyan
    I am using custom font for label and string which I am getting from unicode characters. And the font is not changing. here is the snippet of my code: NSString* str = @"\u05D0\u05D1\u05D2"; [mMatchingLabel setText:str]; mMatchingLabel.font = [UIFont fontWithName:@"David New Hebrew" size:26]; But when I write for example : NSString* str = @"label"; [mMatchingLabel setText:str]; mMatchingLabel.font = [UIFont fontWithName:@"David New Hebrew" size:26]; The font effect is evident. Can someone explain what's here wrong?

    Read the article

  • convert int to string for use in allegro function

    - by ace
    I am trying to run the following code using allegro. textout_ex(screen, font, numbComments , 100, 100, GREEN, BLACK); numbComments is an integer, the function prototype of this function is void textout_ex(BITMAP *bmp, const FONT *f, const char *s, int x, int y, int color, int bg); and i cannot, according to my understanding pass this integer in the third position. I therefore need to convert the integer into a string. I did it like this, but it didnt work. Help please? int score = numbComments; string Str; stringstream out; // YOU MUST INCLUDE <sstream> FOR THIS. out << score; Str = out.str(); and then tried to use the string Str, which didnt work

    Read the article

  • Should I return an NSMutableString in a method that returns NSString

    - by Casey Marshall
    Ok, so I have a method that takes an NSString as input, does an operation on the contents of this string, and returns the processed string. So the declaration is: - (NSString *) processString: (NSString *) str; The question: should I just return the NSMutableString instance that I used as my "work" buffer, or should I create a new NSString around the mutable one, and return that? So should I do this: - (NSString *) processString: (NSString *) str { NSMutableString *work = [NSMutableString stringWithString: str]; // process 'work' return work; } Or this: - (NSString *) processString: (NSString *) str { NSMutableString *work = [NSMutableString stringWithString: str]; // process 'work' return [NSString stringWithString: work]; // or [work stringValue]? } The second one makes another copy of the string I'm returning, unless NSString does smart things like copy-on-modify. But the first one is returning something the caller could, in theory, go and modify later. I don't care if they do that, since the string is theirs. But are there valid reasons for preferring the latter form over the former? And, is either stringWithString or stringValue preferred over the other?

    Read the article

  • Socket.recv works but not gets or read?

    - by Earlz
    Hello I've been messing around with Sockets in Ruby some and came across some example code that I tried modifying and broke. I want to know why it's broken. Server: require "socket" dts = TCPServer.new('127.0.0.1', 20000) loop do Thread.start(dts.accept) do |s| print(s, " is accepted\n") s.write(Time.now) print(s, " is gone\n") s.close end end Client that works: require 'socket' streamSock = TCPSocket.new( "127.0.0.1", 20000 ) streamSock.print( "Hello\n" ) str = streamSock.recv( 100 ) print str streamSock.close Client that is broken require 'socket' streamSock = TCPSocket.new( "127.0.0.1", 20000 ) streamSock.print( "Hello\n" ) str=streamSock.read #this line modified print str streamSock.close I know that the streamSock.print is unnecessary (as well as the naming scheme being non-ruby) but I don't understand why read doesn't work while recv does, Why is this?

    Read the article

  • why is internet explorer displaying my javascript pagination backwards?

    - by user278457
    Here's a version of the code I'm using, stripped down to just the parts that aren't working. This is all written to generate some basic pagination with jQuery. In Chrome/Safari/Moz, I generate see spans, 1,2,3,4,...,etc When I look in IE7/8, I see etc,...,4,3,2,1 The string seems to be concatenating backwards!! This seems very strange to me, because there's not a whole lot going on in the code here, I can't figure out which bit could be causing problems. Obviously, the 1,2,3,4,...,etc is what I'm aiming for here, so as well as an explanation of why this is an issue, I'd love it if someone could offer a quick fix. myVar = { arr:$.makeArray($('.my_li')) }; var str; str=''; for (s in myVar.arr){ r=parseInt(s,10)+1; str+='<span class="my_class">'+r+'</span>'; } $('#my_other_div').html(str);

    Read the article

  • Problem of using cin twice.

    - by gc
    Here is the code: string str; cinstr; cout<<"first input:"<<str<<endl; getline(cin, str); cout<<"line input:"<<str<<endl; The result is that getline never pauses for user input, therefore the second output is always empty. After spending some time on it, I realized after the first call "cinstr", it seems '\n' is still stored in cin (using cin.peek() to check), which ends getline immediately. The solution will be adding one more line between the first usage and the second one: cin.ignore(numeric_limits::max(), '\n'); However, I still don't understand, why is '\n' left there after the first call? What does istream& operator really do?

    Read the article

  • C++ Check Substring of a String

    - by user69514
    I'm trying to check whether or not the second argument in my program is a substring of the first argument. The problem is that it only work if the substring starts with the same letter of the string. .i.e Michigan - Mich (this works) Michigan - Mi (this works) Michigan - igan (this doesn't work) #include <stdio.h> #include <string.h> #include <string> using namespace std; bool my_strstr( string str, string sub ) { bool flag = true; int startPosition = -1; char subStart = str.at(0); char strStart; //find starting position for(int i=0; i<str.length(); i++){ if(str.at(i) == subStart){ startPosition = i; break; } } for(int i=0; i<sub.size(); i++){ if(sub.at(i) != str.at(startPosition)){ flag = false; break; } startPosition++; } return flag; } int main(int argc, char **argv){ if (argc != 3) { printf ("Usage: check <string one> <string two>\n"); } string str1 = argv[1]; string str2 = argv[2]; bool result = my_strstr(str1, str2); if(result == 1){ printf("%s is a substring of %s\n", argv[2], argv[1]); } else{ printf("%s is not a substring of %s\n", argv[2], argv[1]); } return 0; }

    Read the article

  • jQuery sortColumns plugin: How to sort correctly with rowspan

    - by Thang Pham
    Following this post jQuery table sort (github link: https://github.com/padolsey/jQuery-Plugins/blob/master/sortElements/jquery.sortElements.js), I am successfully sort columns, however it does not work in the case of rowspan: For example, case like this Grape 3,096,671M 1,642,721M Apple 2,602,750M 3,122,020M When I click on the second column, it try to sort Apple 2,602,750M 1,642,721M Grape 3,096,671M 3,122,020M which as you can see is not correct, please any jQuery guru help me fix this problem. Here is my code var inverse = false; function sortColumn(index){ index = index + 1; var table = jQuery('#resultsTable'); table.find('td').filter(function(){ return jQuery(this).index() == index; }).sortElements(function(a, b){ a = convertToNum($(a).text()); b = convertToNum($(b).text()); return ( isNaN(a) || isNaN(b) ? a > b : +a > +b ) ? inverse ? -1 : 1 : inverse ? 1 : -1; },function(){ return this.parentNode; }); inverse = !inverse; } function convertToNum(str){ if(isNaN(str)){ var holder = ""; for(i=0; i<str.length; i++){ if(!isNaN(str.charAt(i))){ holder += str.charAt(i); } } return holder; }else{ return str; } } Question: 1.How do I sort this with rowspan. THE NUMBER OF ROWSPAN IS NOT ALWAYS THE SAME. The above example both Grape and Apple have rowspan of 2, but this is not always the case. 2.Can any explain this syntax: return ( isNaN(a) || isNaN(b) ? a > b : +a > +b ) ? inverse ? -1 : 1 : inverse ? 1 : -1; So I can see that if either a or b is not a number, then do string comparison otherwise do number comparison, but I dont understand the inverse ? -1 : 1 : inverse ? 1 : -1;

    Read the article

  • How to share a variable between two classes?

    - by Altefquatre
    How would you share the same object between two other objects? For instance, I'd like something in that flavor: class A { private string foo_; // It could be any other class/struct too (Vector3, Matrix...) public A (string shared) { this.foo_ = shared; } public void Bar() { this.foo_ = "changed"; } } ... // inside main string str = "test"; A a = new A(str); Console.WriteLine(str); // "test" a.Bar(); Console.WriteLine(str); // I get "test" instead of "changed"... :( I read there is some ref/out stuff, but I couldn't get what I'm asking here. I could only apply some changes in the methods scope where I was using ref/out arguments... I also read we could use pointers, but is there no other way to do it?

    Read the article

  • Determine if a string contains only alphanumeric characters (or a space)

    - by dreamlax
    I'm learning C++ and I am writing a function that determines whether a string contains only alphanumeric characters and spaces. I suppose I am effectively testing whether it matches the regular expression ^[[:alnum:] ]+$ but without using regular expressions. I have seen a lot of algorithms revolve around iterators, so I tried to find a solution that made use of iterators, and this is what I have: #include <algorithm> static inline bool is_not_alnum_space(char c) { return !(isalpha(c) || isdigit(c) || (c == ' ')); } bool string_is_valid(const std::string &str) { return find_if(str.begin(), str.end(), is_not_alnum_space) == str.end(); } Is there a better solution, or a “more C++” way to do this?

    Read the article

  • Jakarta Regexp 1.5 Backreferences?

    - by Matt Smith
    Why does this match: String str = "099.9 102.2" + (char) 0x0D; RE re = new RE("^([0-9]{3}.[0-9]) ([0-9]{3}.[0-9])\r$"); System.out.println(re.match(str)); But this does not: String str = "099.9 102.2" + (char) 0x0D; RE re = new RE("^([0-9]{3}.[0-9]) \1\r$"); System.out.println(re.match(str)); The back references don't seem to be working... What am I missing?

    Read the article

  • struct and rand()

    - by teoz
    I have a struct with an array of 100 int (b) and a variable of type int (a) I have a function that checks if the value of "a" is in the array and i have generated the array elements and the variable with random values. but it doesn't work can someone help me fix it? #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct { int a; int b[100]; } h; int func(h v){ int i; for (i=0;i<100;i++){ if(v.b[i]==v.a) return 1; else return 0; } } int main(int argc, char** argv) { h str; srand(time(0)); int i; for(i=0;0<100;i++){ str.b[i]=(rand() % 10) + 1; } str.a=(rand() % 10) + 1; str.a=1; printf("%d\n",func(str)); return 0; }

    Read the article

  • Python 3.3 Webserver restarting problems

    - by IPDGino
    I have made a simple webserver in python, and had some problems with it before as described here: Python (3.3) Webserver script with an interesting error In that question, the answer was to use a While True: loop so that any crashes or errors would be resolved instantly, because it would just start itself again. I've used this for a while, and still want to make the server restart itself every few minutes, but on Linux for some reason it won't work for me. On windows the code below works fine, but on linux it keeps saying Handler class up here ... ... class Server: def __init__(self): self.server_class = HTTPServer self.server_adress = ('MY IP GOES HERE, or localhost', 8080) global httpd httpd = self.server_class(self.server_adress, Handler) self.main() def main(self): if count > 1: global SERVER_UP_SINCE HOUR_CHECK = int(((count - 1) * RESTART_INTERVAL) / 60) SERVER_UPTIME = str(HOUR_CHECK) + " MINUTES" if HOUR_CHECK > 60: minutes = int(HOUR_CHECK % 60) hours = int(HOUR_CHECK // 60) SERVER_UPTIME = ("%s HOURS, %s MINUTES" % (str(hours), str(minutes))) SERVING_ON_ADDR = self.server_adress SERVER_UP_SINCE = str(SERVER_UP_SINCE) SERVER_RESTART_NUMBER = count - 1 print(""" SERVER INFO ------------------------------------- SERVER_UPTIME: %s SERVER_UP_SINCE: %s TOTAL_FILES_SERVED: %d SERVING_ON_ADDR: %s SERVER_RESTART_NUMBER: %s \n\nSERVER HAS RESTARTED """ % (SERVER_UPTIME, SERVER_UP_SINCE, TOTAL_FILES, SERVING_ON_ADDR, SERVER_RESTART_NUMBER)) else: print("SERVER_BOOT=1\nSERVER_ONLINE=TRUE\nRESTART_LOOP=TRUE\nSERVING_ON_ADDR:%s" % str(self.server_adress)) while True: try: httpd.serve_forever() except KeyboardInterrupt: print("Shutting down...") break httpd.shutdown() httpd.socket.close() raise(SystemExit) return def server_restart(): """If you want the restart timer to be longer, replace the number after the RESTART_INTERVAL variable""" global RESTART_INTERVAL RESTART_INTERVAL = 10 threading.Timer(RESTART_INTERVAL, server_restart).start() global count count = count + 1 instance = Server() if __name__ == "__main__": global SERVER_UP_SINCE SERVER_UP_SINCE = strftime("%d-%m-%Y %H:%M:%S", gmtime()) server_restart() Basically, I make a thread to restart it every 10 seconds (For testing purposes) and start the server. After ten seconds it will say File "/home/username/Desktop/Webserver/server.py", line 199, in __init__ httpd = self.server_class(self.server_adress, Handler) File "/usr/lib/python3.3/socketserver.py", line 430, in __init__ self.server_bind() File "/usr/lib/python3.3/http/server.py", line 135, in server_bind socketserver.TCPServer.server_bind(self) File "/usr/lib/python3.3/socketserver.py", line 441, in server_bind self.socket.bind(self.server_address) OSError: [Errno 98] Address already in use As you can see in the except KeyboardInterruption line, I tried everything to make the server stop, and the program stop, but it will NOT stop. But the thing I really want to know is how to make this server able to restart, without giving some wonky errors.

    Read the article

  • Javascript callback function does not work in IE8!

    - by Abhishek
    I have a callback function in my open social application which fetches remote date. This works perfect on Crome and Mozila browers but not in IE8. Following is the example for the same, help will be appriciated: This funcation: gadgets.io.makeRequest(url, response, params) makes the callback call and following function process the responce: function response(obj) { var str = obj.text; var offerDtlPg = str.substr(0, str.length); document.getElementById('pplOfrDetls').innerHTML = offerDtlPg; };

    Read the article

  • simple question on C

    - by lego69
    I have this snippet of the code char *str = “123”; if(str[0] == 1) printf("Hello\n"); why I can't receive my Hello thanks in advance! how exactly compiler does this comparison if(str[0] == 1)?

    Read the article

  • [PHP] strtr function OS-reltated problem

    - by Casidiablo
    Hello there! I have this funtion that converts all special chars to uppercase: function uc_latin1($str) { if(!defined("LATIN1_UC_CHARS")) define("LATIN1_UC_CHARS", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ"); if(!defined("LATIN1_LC_CHARS")) define("LATIN1_LC_CHARS", "àáâãäåæçèéêëìíîïðñòóôõöøùúûüý"); $str = strtoupper ( strtr ( $str, LATIN1_LC_CHARS, LATIN1_UC_CHARS ) ); return $str; } This function works fine in my development PC (which runs Windows XP)... but, when I test it in the production server (running Redhat Linux) it does not uppercase the string. The string is ISO-8859-1 encoded. How can I make it work in Linux too? Thanks for reading.

    Read the article

  • Custom string class (C++)

    - by Sanctus2099
    Hey guys. I'm trying to write my own C++ String class for educational and need purposes. The first thing is that I don't know that much about operators and that's why I want to learn them. I started writing my class but when I run it it blocks the program but does not do any crash. Take a look at the following code please before reading further: class CString { private: char* cstr; public: CString(); CString(char* str); CString(CString& str); ~CString(); operator char*(); operator const char*(); CString operator+(const CString& q)const; CString operator=(const CString& q); }; First of all I'm not so sure I declared everything right. I tried googleing about it but all the tutorials about overloading explain the basic ideea which is very simple but lack to explain how and when each thing is called. For instance in my = operator the program calls CString(CString& str); but I have no ideea why. I have also attached the cpp file below: CString::CString() { cstr=0; } CString::CString(char *str) { cstr=new char[strlen(str)]; strcpy(cstr,str); } CString::CString(CString& q) { if(this==&q) return; cstr = new char[strlen(q.cstr)+1]; strcpy(cstr,q.cstr); } CString::~CString() { if(cstr) delete[] cstr; } CString::operator char*() { return cstr; } CString::operator const char* () { return cstr; } CString CString::operator +(const CString &q) const { CString s; s.cstr = new char[strlen(cstr)+strlen(q.cstr)+1]; strcpy(s.cstr,cstr); strcat(s.cstr,q.cstr); return s; } CString CString::operator =(const CString &q) { if(this!=&q) { if(cstr) delete[] cstr; cstr = new char[strlen(q.cstr)+1]; strcpy(cstr,q.cstr); } return *this; } For testing I used a code just as simple as this CString a = CString("Hello") + CString(" World"); printf(a); I tried debugging it but at a point I get lost. First it calls the constructor 2 times for "hello" and for " world". Then it get's in the + operator which is fine. Then it calls the constructor for the empty string. After that it get's into "CString(CString& str)" and now I'm lost. Why is this happening? After this I noticed my string containing "Hello World" is in the destructor (a few times in a row). Again I'm very puzzeled. After converting again from char* to Cstring and back and forth it stops. It never get's into the = operator but neither does it go further. printf(a) is never reached. I use VisualStudio 2010 for this but it's basically just standard c++ code and thus I don't think it should make that much of a difference

    Read the article

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