Search Results

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

Page 188/245 | < Previous Page | 184 185 186 187 188 189 190 191 192 193 194 195  | Next Page >

  • Fastest algorithm to check if a number is pandigital?

    - by medopal
    Pandigital number is a number that contains the digits 1..number length. For example 123, 4312 and 967412385. I have solved many Project Euler problems, but the Pandigital problems always exceed the one minute rule. This is my pandigital function: private boolean isPandigital(int n){ Set<Character> set= new TreeSet<Character>(); String string = n+""; for (char c:string.toCharArray()){ if (c=='0') return false; set.add(c); } return set.size()==string.length(); } Create your own function and test it with this method int pans=0; for (int i=123456789;i<=123987654;i++){ if (isPandigital(i)){ pans++; } } Using this loop, you should get 720 pandigital numbers. My average time was 500 millisecond. I'm using Java, but the question is open to any language.

    Read the article

  • How I change a variable of a type to another one in C?

    - by drigoSkalWalker
    I want to do it: int main () { bla bla bla void *onetype; switch (USER_INPUT_TYPE) { CASE CONVERT_TO_CHAR: convert onetype VOID TO CHAR >>> HOW??? CASE CONVERT_TO_INT: convert onetype VOID TO INT >>> HOW??? LOT OF CASES... } } Yes, I know type casting, but type casting is a 'temporary' change. So, is there any way to accomplish it in C? EDIT : Stop stop stop! Please, see, what are you doing is type casting, I KNOW THIS, you are creating another variable of the desirable type like int i = (int) onetype, I don't want this, I want something else like onetype = (int) onetype, without recreate them, without allocate another variable. Thanks a lot guys!

    Read the article

  • How to do rolling balances in Linq2SQL

    - by David Liddle
    Given an account with a list of transactions I would like to output a query that shows each transaction with the rolling balance (just like you would see on an online banking account). TRANSACTIONS - ID - DATE - AMOUNT Here is what I created in T-SQL however was wondering if this can be translated to linq2sql code? select T.ID, convert(char(10), T.DATE, 101) as 'DATE', T.AMOUNT, (select sum(O.AMOUNT) from TRANSACTIONS O where O.DATE < T.DATE or (O.DATE = T.DATE and O.ID <= T.ID)) 'BALANCE' from TRANSACTIONS as T where T.DATE between @pStartDate and @pEndDate order by T.DATE, T.ID Alternatively I guess my other option is to just call a stored procedure for these kind of results. However, I have Services which call Repositories and didn't really want to put the sproc call in the Repository.

    Read the article

  • Why would you precede the main() function in C with a data type?

    - by Milktrader
    Many are familiar with the hello world program in C #include <stdio.h> main () { printf ("hello world"); return 0; } Why do some precede the main () function with int as in: int main() Also, I've seen the word 'void' entered inside the () as in: int main(void) It seems like extra typing for nothing, but maybe it's a best practice that pays dividends in other situations? Also, why precede main() with an int if you're returning a character string? If anything, one would expect: char main(void) I'm also foggy about why we return 0 at the end of the function.

    Read the article

  • Obtaining command line arguments in a QT console app

    - by morpheous
    The following snippet is from a little console app I wrote using the QT framework. Currently, it does not receive the arguments passed at the CLI. Can anyone spot what I may be doing wrong? int main(int argc, char *argv[]) { //Q_INIT_RESOURCE(application); try { QApplication the_app(argc, argv); utility::option_values ov; QStringList cmdline_args = QCoreApplication::arguments(); //attempt to parse arguments here, but cmdline_args is an empty list :( ov.parse_options(cmdline_args); // Code continues ... } } catch (utility::invalid_option&) { return 1; } return 0; } I am debugging using QtCreator 1.3

    Read the article

  • Stringification of a macro value

    - by SF.
    I faced a problem - I need to use a macro value both as string and as integer. #define RECORDS_PER_PAGE 10 /*... */ #define REQUEST_RECORDS \ "SELECT Fields FROM Table WHERE Conditions" \ " OFFSET %d * " #RECORDS_PER_PAGE \ " LIMIT " #RECORDS_PER_PAGE ";" char result_buffer[RECORDS_PER_PAGE][MAX_RECORD_LEN]; /* ...and some more uses of RECORDS_PER_PAGE, elsewhere... */ This fails with a message about "stray #", and even if it worked, I guess I'd get the macro names stringified, not the values. Of course I can feed the values to the final method ( "LIMIT %d ", page*RECORDS_PER_PAGE ) but it's neither pretty nor efficient. It's times like this when I wish the preprocessor didn't treat strings in a special way and would process their content just like normal code. For now, I cludged it with #define RECORDS_PER_PAGE_TXT "10" but understandably, I'm not happy about it. How to get it right?

    Read the article

  • C - Call a function

    - by Pedro
    Hello. I want to get a value from a function in other function i think i have to call a function in other function, then call it on main, but how? void funcA(PEOPLE people[], int *total){ FILE *fp; char line[100]; fp=fopen("example.txt","r"); if(fp==NULL){ exit(1); } else{ fgets(line, 100, fp);//get a number from the txt total=atoi(linha);//convert to int } } void funcB(PEOPLE people[], int *total){ int i; for(i=0;i<total;i++){ printf("%s\n",people[i].name); } funcA(people,&total); } void main(){ PERSON person[100]; int *total; funcB(people,&total); } What i'm doing wrong?

    Read the article

  • SQL Server 2008 Stored Procedure

    - by user238319
    I cannot store the date data type variables using stored procedure. My code is: ALTER PROCEDURE [dbo].[Access1Register] -- Add the parameters for the stored procedure here @MobileNumber int, @CitizenName varchar(50), @Dob char(8), @VerificationCode int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here select CAST(@dob As DATE) Insert Into Access1 (MobileNo,CitizenName,Dob,VerificationCode) values(@MobileNumber,@CitizenName,@Dob,@VerificationCode) go If I exec this procedure it is executing, but there is an error occured in the date type variable. It's raising the error as invalid item '-'.

    Read the article

  • Index out of bounds exception in c#

    - by Naga
    I have the following code in my program which is throwing index out of bound exception at line yearList.SetValue(years[count], count); protected void invoiceYear_DataBound(object sender, EventArgs e) { //invoiceYear.SelectedItem.Value= GetYearRange(); String[] years = GetYearRange().Split(new char[] { '[', ',', ']',' ' }); ListItem [] yearList = new ListItem[]{}; System.Diagnostics.Debug.WriteLine("years-->" + years.Length); for (int i = 0; i < years.Length; i++) { System.Diagnostics.Debug.WriteLine("years-->" + years.GetValue(i)); } int count = 0; foreach (String str in years) { if (string.IsNullOrEmpty(str)) System.Diagnostics.Debug.WriteLine("empty"); else { yearList.SetValue(years[count], count); count++; } } //System.Diagnostics.Debug.WriteLine("yearList-->" + yearList.GetValue(0)); //invoiceYear.Items.AddRange(yearList); }

    Read the article

  • Is there any way to pass an anonymous array as an argument in C++?

    - by Jeremy Friesner
    Hi all, I'd like to be able to declare an array as a function argument in C++, as shown in the example code below (which doesn't compile). Is there any way to do this (other than declaring the array separately beforehand)? #include <stdio.h> static void PrintArray(int arrayLen, const int * array) { for (int i=0; i<arrayLen; i++) printf("%i -> %i\n", i, array[i]); } int main(int, char **) { PrintArray(5, {5,6,7,8,9} ); // doesn't compile return 0; }

    Read the article

  • How to cast a character to int in Clojure?

    - by Learning Clojure
    How to cast a character to int in Clojure? I am trying to write a rot 13 in clojure, so I need to have something to cast my char to int. I found something called (int), so I put: (int a) Get: CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:13:1) Then I put: (int 'a) Get: ClassCastException clojure.lang.Symbol cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) Then: (rot13 ''a') Get: ClassCastException clojure.lang.PersistentList cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) And: (rot13 "a") Get: ClassCastException java.lang.String cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) So what is the right way to do it? btw, I always get confused with all these clojure syntax. But I can never find any source only help me with my problem. Any suggestions? Thank you!!

    Read the article

  • SQL query error while trying to put a file in the database

    - by DaGhostman Dimitrov
    Hey Guys I have a big problem that I have no Idea why.. I have few forms that upload files to the database, all of them work fine except one.. I use the same query in all(simple insert). I think that it has something to do with the files i am trying to upload but I am not sure. Here is the code: if ($_POST['action'] == 'hndlDocs') { $ref = $_POST['reference']; // Numeric value of $doc = file_get_contents($_FILES['doc']['tmp_name']); $link = mysqli_connect('localhost','XXXXX','XXXXX','documents'); mysqli_query($link,"SET autocommit = 0"); $query = "INSERT INTO documents ({$ref}, '{$doc}', '{$_FILES['doc']['type']}') ;"; mysqli_query($link,$query); if (mysqli_error($link)) { var_dump(mysqli_error($link)); mysqli_rollback($link); } else { print("<script> window.history.back(); </script>"); mysqli_commit($link); } } The database has only these fields: DATABASE documents ( reference INT(5) NOT NULL, //it is unsigned zerofill doc LONGBLOB NOT NULL, //this should contain the binary data mime_type TEXT NOT NULL // the mime type of the file php allows only application/pdf and image/jpeg ); And the error I get is : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00001, '????' at line 1 I will appreciate every help. Cheers!

    Read the article

  • How can you get the first digit in an int (C#)?

    - by Dinah
    In C#, what's the best way to get the 1st digit in an int? The method I came up with is to turn the int into a string, find the 1st char of the string, then turn it back to an int. int start = Convert.ToInt32(curr.ToString().Substring(0, 1)); While this does the job, it feels like there is probably a good, simple, math-based solution to such a problem. String manipulation feels clunky. Edit: irrespective of speed differences, mystring[0] instead of Substring() is still just string manipulation

    Read the article

  • Table character encoding - exception in application

    - by zgnilec
    I have a code: CREATE TABLE IF NOT EXISTS Person ( name varchar(24) ... ) CHARACTER SET utf8 COLLATE utf8_polish_ci; This works OK in my application, but I read if someone put in name field a string that contains character wchich code is greater than 127, database will use 2 bytes (or more) to store this character. So i think, i will change character set to utf16: CHARACTER SET utf16 COLLATE utf16_polish_ci; But now when I run my application, exception apears: KeyNotFoundException. It apears exactly at these instructions: MySqlCommand komenda = baza.Polaczenie.CreateCommand (); komenda.CommandText = zapytanie; MySqlDataReader dr = komenda.ExecuteReader (); // HERE, at execute reader method if (dr.Read ()) ... 1) Anyone had similar problem? 2) Any idea how to use always 2 bytes/char in database field?

    Read the article

  • Porting Python algorithm to C++ - different solution

    - by cb0
    Hello, I have written a little brute string generation script in python to generate all possible combinations of an alphabet within a given length. It works quite nice, but for the reason I wan't it to be faster I try to port it to C++. The problem is that my C++ Code is creating far too much combination for one word. Heres my example in python: ./test.py gives me aaa aab aac aad aa aba .... while ./test (the c++ programm gives me) aaa aaa aaa aaa aa Here I also get all possible combinations, but I get them twice ore more often. Here is the Code for both programms: #!/usr/bin/env python import sys #Brute String Generator #Start it with ./brutestringer.py 4 6 "abcdefghijklmnopqrstuvwxyz1234567890" "" #will produce all strings with length 4 to 6 and chars from a to z and numbers 0 to 9 def rec(w, p, baseString): for c in "abcd": if (p<w - 1): rec(w, p + 1, baseString + "%c" % c) print baseString for b in range(3,4): rec(b, 0, "") And here the C++ Code #include <iostream> using namespace std; string chars="abcd"; void rec(int w,int b,string p){ unsigned int i; for(i=0;i<chars.size();i++){ if(b < (w-1)){ rec(w, (b+1), p+chars[i]); } cout << p << "\n"; } } int main () { int a=3, b=0; rec (a+1,b, ""); return 0; } Does anybody see my fault ? I don't have much experience with C++. Thanks indeed

    Read the article

  • function to remove duplicate characters in a string

    - by Codenotguru
    The following code is trying to remove any duplicate characters in a string.Iam not sure if the code is right??Can anybody help me with the working of the code i.e whats actually happening when there is a match in characters? public static void removeDuplicates(char[] str) { if (str == null) return; int len = str.length; if (len < 2) return; int tail = 1; for (int i = 1; i < len; ++i) { int j; for (j = 0; j < tail; ++j) { if (str[i] == str[j]) break; } if (j == tail) { str[tail] = str[i]; ++tail; } } str[tail] = 0; }

    Read the article

  • How to use #ifdef entities as part of functions in header files

    - by Crazyjavahacking
    I would like to ask if it is possible to use the entities defined in #ifdef block in header files. To be clear, I have following code: #ifdef #include <winsock2.h> #define SOCKET_HANDLE SOCKET #define CONNECTION_HANDLE SOCKET #endif SOCKET_HANDLE createServerSocket(const char* hostAddress, short port); I am Java developer and this seems completely fine for me. However compiler has a problem with this. Can you explain why is that code a problem? Also how can I force to compile it. (The idea is to have generic interface and conditional compilation to determine real types according to running platform at compile time.) Thanks

    Read the article

  • What data stucture should I use for BigInt class

    - by user1086004
    I would like to implement a BigInt class which will be able to handle really big numbers. I want only to add and multiply numbers, however the class should also handle negative numbers. I wanted to represent the number as a string, but there is a big overhead with converting string to int and back for adding. I want to implement addition as on the high school, add corresponding order and if the result is bigger than 10, add the carry to next order. Then I thought that it would be better to handle it as a array of unsigned long long int and keep the sign separated by bool. With this I'm afraid of size of the int, as C++ standard as far as I know guarantees only that int < float < double. Correct me if I'm wrong. So when I reach some number I should move in array forward and start adding number to the next array position. Is there any data structure that is appropriate or better for this? Thanks in advance.

    Read the article

  • Delete on a very deep tree

    - by Kathoz
    I am building a suffix trie (unfortunately, no time to properly implement a suffix tree) for a 10 character set. The strings I wish to parse are going to be rather long (up to 1M characters). The tree is constructed without any problems, however, I run into some when I try to free the memory after being done with it. In particularly, if I set up my constructor and destructor to be as such (where CNode.child is a pointer to an array of 10 pointers to other CNodes, and count is a simple unsigned int): CNode::CNode(){ count = 0; child = new CNode* [10]; memset(child, 0, sizeof(CNode*) * 10); } CNode::~CNode(){ for (int i=0; i<10; i++) delete child[i]; } I get a stack overflow when trying to delete the root node. I might be wrong, but I am fairly certain that this is due to too many destructor calls (each destructor calls up to 10 other destructors). I know this is suboptimal both space, and time-wise, however, this is supposed to be a quick-and-dirty solution to a the repeated substring problem. tl;dr: how would one go about freeing the memory occupied by a very deep tree? Thank you for your time.

    Read the article

  • Is `auto int i` valid C++0x?

    - by Motti
    In answering this question the question arose as to whether the traditional C meaning of the keyword auto (automatic storage) is still valid in C++0x now that it means type deduction. I remember that the old meaning of auto should remain where relevant but others disagreed. auto char c = 42; // either compilation error or c = '*' Looking at compilers I see the current division. Old meaning of auto is no longer allowed VS10 g++ Old meaning of auto is used where relevant Comeau Do you know which is the correct behaviour?

    Read the article

  • Obj-c Turning long string into multidimensional array

    - by Phil
    I have a long NSString, something like "t00010000t00020000t00030000" and so on. I need to split that up into each "t0001000". I'm using... NSArray *tileData = [[GameP objectForKey:@"map"] componentsSeparatedByString:@"t"]; And it splits it up, but the "t" is missing, which I need (although I think I could append it back on). The other way I guess would be to split it up by counting 8 char's, although not sure how to do that. But ideally I need it split into a [][] type array so I can get to each bit with something like... NSString tile = [[tileData objectAtIndex:i] objectAtIndex:j]]; I'm new to obj-c so thanks for any help.

    Read the article

  • [C] How I change a variable of a type to another one?

    - by drigoSkalWalker
    I want to do it: int main () { bla bla bla void *onetype; switch (USER_INPUT_TYPE) { CASE CONVERT_TO_CHAR: convert onetype VOID TO CHAR HOW??? CASE CONVERT_TO_INT: convert onetype VOID TO INT HOW??? LOT OF CASES... } } Yes, I know type casting, but type casting is a 'temporary' change... So...Is there any way to accomplish it in C? EDIT : Stop stop stop! Please, see, what are you doing is type casting, I KNOW THIS, you are creating another variable of the desirable type like int i = (int) onetype, I don't want this, I want something else like onetype = (int) onetype, without recreate them, without allocate another variable. Thanks a lot guys!

    Read the article

  • The unary increment operator in pointer arithmetic

    - by RhymesWithDuck
    Hello, this is my first post. I have this function for reversing a string in C that I found. void reverse(char* c) { if (*c != 0) { reverse(c + 1); } printf("%c",*c); } It works fine but if I replace: reverse(c + 1); with: reverse(++c); the first character of the original string is truncated. My question is why would are the statements not equivalent in this instance? Thanks

    Read the article

  • Beginner C: error: control reaches end of non-void function?

    - by Ting
    I'm trying to make a greedy algorithm and I get this error: greedy2.c:27:1: error: control reaches end of non-void function [-Werror,-Wreturn-type] } ^ 1 error generated. with this code: int man(int argc, char* argv[]) { float amount; do { printf("Input dollar amount owed:\n"); amount = GetFloat(); } while (amount <= 0); int coins = 0; while (amount >= 0.25); { amount = amount - 0.25; coins++; } printf("Number of coins to use: %d\n", coins); } What is wrong with my curly braces, and how do I fix it?

    Read the article

  • How to generate random strings that match a given regexp?

    - by Pies
    Duplicate: Random string that matches a regexp No, it isn't. I'm looking for an easy and universal method, one that I could actually implement. That's far more difficult than randomly generating passwords. I want to create an application that takes a regular expression, and shows 10 randomly generated strings that match that expression. It's supposed to help people better understand their regexps, and to decide i.e. if they're secure enough for validation purposes. Does anyone know of an easy way to do that? One obvious solution would be to write (or steal) a regexp parser, but that seems really over my head. I repeat, I'm looking for an easy and universal way to do that. Edit: Brute force approach is out of the question. Assuming the random strings would just be [a-z0-9]{10} and 1 million iterations per second, it would take 65 years to iterate trough the space of all 10-char strings.

    Read the article

< Previous Page | 184 185 186 187 188 189 190 191 192 193 194 195  | Next Page >