Search Results

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

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

  • Implementing Object Oriented: ansi-C approach

    - by No Money
    Hey there, I am an Intermediate programmer in Java and know some of the basics in C++. I recently started to scam over "C language" [please note that i emphasized on C language and want to stick with C as i found it to be a perfect tool, so no need for suggestions focusing on why should i move back to C++ or Java or any other crappy language (e.g: C#)]. Moving on, I code an Object Oriented approach in C but kindda scramble with the pointers part. Please understand that I am just a noob trying to extend my knowledge beyond what i learned in High School. Here is my code..... #include <stdio.h> typedef struct per{ int privateint; char *privateString; struct per (*New) (); void (*deleteperOBJ) (struct t_person *); void (*setperNumber) ((struct*) t_person,int); void (*setperString) ((struct*) t_person,char *); void (*dumpperState) ((struct*) t_person); }t_person; void setperNumber(t_person *const per,int num){ if(per==NULL) return; per->privateint=num; } void setperString(t_person *const per,char *string){ if(per==NULL) return; per->privateString=string; } void dumpperState(t_person *const per){ if(per==NULL) return; printf("value of private int==%d\n", per->privateint); printf("value of private string==%s\n", per->privateString); } void deleteperOBJ(struct t_person *const per){ free((void*)t_person->per); t_person ->per = NULL; } main(){ t_person *const per = (struct*) malloc(sizeof(t_person)); per = t_person -> struct per -> New(); per -> setperNumber (t_person *per, 123); per -> setperString(t_person *per, "No money"); dumpperState(t_person *per); deleteperOBJ(t_person *per); } Just to warn you, this program has several errors and since I am a beginner I couldn't help except to post this thread as a question. I am looking forward for assistance. Thanks in advance.

    Read the article

  • PLEASE HELP JAVA/SQL question

    - by fred-ghosn
    Hello everyone, well I'm new here and I really need some help.. I want to create a table and this table's name will be inserted from a textfield. However when I run the query it's giving me an error, any help on this one? Ill paste the code here: public boolean CreateTable() { TableNumber=jTextField4.getText(); try { String password = null; String s = "CREATE TABLE '"+TableNumber+'" (Item char(50),Price char(50))"; ConnectionForOrders(); stmt = conn.createStatement(); stmt.executeUpdate(s); boolean f=false; ConnectionForOrdersclose();

    Read the article

  • segmentation fault

    - by gcc
    int num_arrays; char *p[20]; char tempc; int i=0; do { p[i]=malloc(sizeof(int)); scanf("%s",p[i]); tempc=p[i]; ++i; }while(tempc=='x'); num_arrays=atoi(p[0]); When i write num_arrays=atoi(..),gcc give me segmentation fault or memory stack is exceeded, I don't understand why it behaves like that can anyone explain, why?

    Read the article

  • Sorting array of structs

    - by mrblippy
    Hi, i am having trouble making a method to sort an array of structs. i am tring to sort them in ascending order based on classcode. any help you could give would be appreciated struct unit { char classcode[4]; char *classname; }; void insertion_sort(struct unit u[], int n) { int j, p; struct unit tmp[1]; for(p = 1; p < n; p++) { tmp[0] = u[p]; for(j = p; j > 0 && (strcmp(tmp[j-1].classcode, tmp[p].classcode) > 0); j--) u[j] = u[j-1]; u[j] = tmp[0]; } }

    Read the article

  • newline character on text area

    - by Prady
    I have a custom field called Current_Address__c which is of datatype textarea. I need to populate this field in the format below. ie a newline char after street and another newline after zip. street City state Zip Country The values of city state zip country etc are been taken from contact object. I dont want to use this as a formula field. So i need to populate it in my controller and display it on my VF page. I am trying to add a newline char by using the code below this.customobj.Current_Address__c = currentStreet + '\\n ' + currentCity + ' ' + currentState + ' ' + currentZIP + '\\n ' + currentCountry ; i had also used \n instead of \n. It still show the field in one line instead of 3 lines

    Read the article

  • Hiredis waiting for message

    - by Vivek Goel
    I am using hiredis C library to connect to redis server. I am not able to figure out how to wait for new messages after subscribing to new message. My code look like: signal(SIGPIPE, SIG_IGN ); struct event_base *base = event_base_new(); redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } redisLibeventAttach(c, base); redisAsyncSetConnectCallback(c, connectCallback); redisAsyncSetDisconnectCallback(c, disconnectCallback); redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1], strlen(argv[argc - 1])); redisAsyncCommand(c, getCallback, (char*) "end-1", "GET key"); redisAsyncCommand(c, getCallback, (char*) "end-1", "SUBSCRIBE foo"); Now how to tell hiredis to wait for message on channel ?

    Read the article

  • C++ - Opening a file inside a function using fopen

    - by Josh
    I am using Visual Studio 2005 (C++). I am passing a string into a function as a char array. I want to open the file passed in as a parameter and use it. I know my code works to an extent, because if I hardcode the filename as the first parameter it works perfectly. I do notice if I look at the value as a watch, the value includes the address aside the string literal. I have tried passing in the filename as a pointer, but it then complains about type conversion with __w64. As I said before it works fine with "filename.txt" in place of fileName. I am stumped. void read(char fileName[50],int destArray[MAX_R][MAX_C],int demSize[2]) { int rows=0; int cols=0; int row=0; int col=0; FILE * f = fopen(fileName,"r"); ...

    Read the article

  • Haskell. Numbers in binary numbers. words

    - by Katja
    Hi! I need to code words into binary numbers. IN: "BCD..." OUT:1011... I have written already funktion for coding characters into siple numbers IN: 'C' OUT: 3 IN: 'c' OUT: 3 lett2num :: Char -> Int lett2num x | (ord 'A' <= ord x) && (ord x <= ord 'Z') = (ord x - ord 'A') + 1 | (ord 'a' <= ord x) && (ord x <= ord 'z') = (ord x - ord 'a') +1 num2lett :: Int -> Char num2lett n | (n <= ord 'A') && (n <= ord 'Z') = chr(ord 'A'+ n - 1) | (n <= ord 'a') && (n <= ord 'Z') = chr(ord 'A'+ n - 1) I wrote as well function for codind simple numbers into binary. num2bin :: Int->[Int] num2bin 0 = [] num2bin n | n>=0 = n `mod` 2 : (num2bin( n `div` 2)) | otherwise = error but I donw want those binary numbers to be in a list how can I get rid of the lists? Thanks

    Read the article

  • Redirecting one file to another using dub2 and strtok

    - by Sergiy Zakharov
    OK, here goes. I have to write a program, in which I need to use strtok and dup2 to redirect one file to another, but I need to also have the user to actually put the command cat < file1 file2, but not from the shell, but instead by using my program. That's why I need strtok. And the reason my program doesn't work is probably because of that, because I don't really understand how strtok works. I found a similar program on the internet, but they just take the ls command and redirect it to the file. That's it. My program is much more complicated. I mean, it would've been easier just to say in shell cat < file1 file2, but for some reason they want us to do it this way. So, anyways, here is what I have so far (here I just combined what I have found on the internet with what I already had from before. We had to do something similar but then the user would just go ls or ls -l. Very simple stuff. This is much harder, for me, at least.) #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <errno.h> #include <sys/wait.h> #include <string.h> int main() { pid_t pid; char line[256]; char *args[129]; int i; int fd; int status; char *temp; while (1) { printf(">"); if (fgets(line, 256, stdin) == 0) { exit(0); } else { pid = fork(); if (pid == 0) { i = 0; temp = strtok("<",line); while (temp != NULL) { args[i++] = temp; temp = strtok(">",line); args[i] = '\0'; } fd = open("hello", O_RDONLY); dup2(fd, STDIN_FILENO); fd = open("world", O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); dup2(fd, STDOUT_FILENO ); close(fd); execvp(args[0], args); } else { close(fd); wait(&status); } } } } Any help would be greatly appreciated.

    Read the article

  • Why does accessing a member of a malloced array of structs seg fault?

    - by WSkinner
    I am working through Learn C The Hard Way and am stumped on something. I've written a simplified version of the problem I am running into to make it easier to get down to it. Here is the code: #include <stdlib.h> #define GROUP_SIZE 10 #define DATA_SIZE 64 struct Dummy { char *name; }; struct Group { struct Dummy **dummies; }; int main() { struct Group *group1 = malloc(sizeof(struct Group)); group1->dummies = malloc(sizeof(struct Dummy) * GROUP_SIZE); struct Dummy *dummy1 = group1->dummies[3]; // Why does this seg fault? dummy1->name = (char *) malloc(DATA_SIZE); return 0; } when I try to set the name pointer on one of my dummies I get a seg fault. Using valgrind it tells me this is uninitialized space. Why is this?

    Read the article

  • Prolog .. Can i convert from a list of chars to a string or term in Prolog !!

    - by AhmadAssaf
    i use read_line_to_codes(Stream,Line) to read a line from a file .. first is there any way to read a line and assign it to a term in prolog ?? if not i managed to read a line and put it in this char list .. now this char list contains spaces .. which is bad .. so i want to convert it to a term or a string in prolog so that i can process it easier .. spaces cannot be atoms so thats a problem .. i appreciate the help !!

    Read the article

  • How to extract img src, title and alt from html using php?

    - by Sam
    I would like to create a page where all images which reside on my website are listed with title and alternative representation. I already wrote me a little program to find and load all html files, but now I am stuck at how to extract src, title and alt from the html < img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a cute little fluffy bunny"/ I guess this should be done with some regex, but since the order of the tags may vary, and I need all of them, I don't really know how to parse this in an elegant way (I could do it the hard char by char way, but thats painful).

    Read the article

  • error in encryption program

    - by Raja
    #include<iostream> #include<math.h> #include<string> using namespace std; int gcd(int n,int m) { if(m<=n && n%m ==0) return m; if(n<m) return gcd(m,n); else return gcd(m,n%m); } int REncryptText(char m) { int p = 11, q = 3; int e = 3; int n = p * q; int phi = (p - 1) * (q - 1); int check1 = gcd(e, p - 1); int check2 = gcd(e, q - 1); int check3 = gcd(e, phi); // // Compute d such that ed = 1 (mod phi) //i.e. compute d = e-1 mod phi = 3-1 mod 20 //i.e. find a value for d such that phi divides (ed-1) //i.e. find d such that 20 divides 3d-1. //Simple testing (d = 1, 2, ...) gives d = 7 // double d = Math.Pow(e, -1) % phi; int d = 7; // public key = (n,e) // (33,3) //private key = (n,d) //(33 ,7) double g = pow(m,e); int ciphertext = g %n; // Now say we want to encrypt the message m = 7, c = me mod n = 73 mod 33 = 343 mod 33 = 13. Hence the ciphertext c = 13. //double decrypt = Math.Pow(ciphertext, d) % n; return ciphertext; } int main() { char plaintext[80],str[80]; cout<<" enter the text you want to encrpt"; cin.get(plaintext,79); int l =strlen(plaintext); for ( int i =0 ; i<l ; i++) { char s = plaintext[i]; str[i]=REncryptText(s); } for ( int i =0 ; i<l ; i++) { cout<<"the encryption of string"<<endl; cout<<str[i]; } return 0; }

    Read the article

  • How to implement square root and exponentiation on arbitrary length numbers?

    - by tomp
    I'm working on new data type for arbitrary length numbers (only non-negative integers) and I got stuck at implementing square root and exponentiation functions (only for natural exponents). Please help. I store the arbitrary length number as a string, so all operations are made char by char. Please don't include advices to use different (existing) library or other way to store the number than string. It's meant to be a programming exercise, not a real-world application, so optimization and performance are not so necessary. If you include code in your answer, I would prefer it to be in either pseudo-code or in C++. The important thing is the algorithm, not the implementation itself. Thanks for the help.

    Read the article

  • emacs: how do I use edebug on code that is defined in a macro?

    - by Cheeso
    I don't even know the proper terminology for this lisp syntax, so I don't know if the words I'm using to ask the question, make sense. But the question makes sense, I'm sure. So let me just show you. cc-mode (cc-fonts.el) has things called "matchers" which are bits of code that run to decide how to fontify a region of code. That sounds simple enough, but the matcher code is in a form I don't completely understand, with babckticks and comma-atsign and just comma and so on, and furthermore it is embedded in a c-lang-defcost, which itself is a macro. And I want to run edebug on that code. Look: (c-lang-defconst c-basic-matchers-after "Font lock matchers for various things that should be fontified after generic casts and declarations are fontified. Used on level 2 and higher." t `(;; Fontify the identifiers inside enum lists. (The enum type ;; name is handled by `c-simple-decl-matchers' or ;; `c-complex-decl-matchers' below. ,@(when (c-lang-const c-brace-id-list-kwds) `((,(c-make-font-lock-search-function (concat "\\<\\(" (c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds)) "\\)\\>" ;; Disallow various common punctuation chars that can't come ;; before the '{' of the enum list, to avoid searching too far. "[^\]\[{}();,/#=]*" "{") '((c-font-lock-declarators limit t nil) (save-match-data (goto-char (match-end 0)) (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start) (c-forward-syntactic-ws)) (goto-char (match-end 0))))))) I am reading up on lisp syntax to figure out what those things are and what to call them, but aside from that, how can I run edebug on the code that follows the comment that reads ;; Fontify the identifiers inside enum lists. ? I know how to run edebug on a defun - just invoke edebug-defun within the function's definition, and off I go. Is there a corresponding thing I need to do to edebug the cc-mode matcher code forms?

    Read the article

  • how to reloadData in tableView when tableview access data from database.

    - by Ajeet Kumar Yadav
    I am new in iphone i am developing a application that take value from data base and display data in tableview. in this application we save data from one data table to other data table this is when add first time work and when we do second time application is crash. how to solve this problem i am not understand code is given bellow my appdelegate code for insert value from one table to other is given bellow -(void)sopinglist { //////databaseName= @"SanjeevKapoor.sqlite"; databaseName =@"AjeetTest.sqlite"; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; databasePath =[documentsDir stringByAppendingPathComponent:databaseName]; [self checkAndCreateDatabase]; list1 = [[NSMutableArray alloc] init]; sqlite3 *database; if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { if(addStmt == nil) { ///////////const char *sql = "insert into Dataa(item) Values(?)"; const char *sql = " insert into Slist select * from alootikki"; ///////////// const char *sql =" Update Slist ( Incredients, Recipename,foodtype) Values(?,?,?)"; if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK) NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database)); } /////for( NSString * j in k) sqlite3_bind_text(addStmt, 1, [k UTF8String], -1, SQLITE_TRANSIENT); //sqlite3_bind_int(addStmt,1,i); // sqlite3_bind_text(addStmt, 1, [coffeeName UTF8String], -1, SQLITE_TRANSIENT); // sqlite3_bind_double(addStmt, 2, [price doubleValue]); if(SQLITE_DONE != sqlite3_step(addStmt)) NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); else //SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid coffeeID = sqlite3_last_insert_rowid(database); //Reset the add statement. sqlite3_reset(addStmt); // sqlite3_clear_bindings(detailStmt); //} } sqlite3_finalize(addStmt); addStmt = nil; sqlite3_close(database); } And the table View code for access data from database is given bellow SanjeevKapoorAppDelegate *appDelegate =(SanjeevKapoorAppDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate sopinglist]; ////[appDelegate recpies]; /// NSArray *a =[[appDelegate list1] componentsJoinedByString:@","]; k= [[appDelegate list1] componentsJoinedByString:@","];

    Read the article

  • Are pointers primitive types in C++?

    - by Space_C0wb0y
    I was wondering about the last constructor for std::string mentioned here. It says: template<class InputIterator> string (InputIterator begin, InputIterator end); If InputIterator is an integral type, behaves as the sixth constructor version (the one right above this) by typecasting begin and end to call it: string(static_cast<size_t>(begin),static_cast<char>(end)); In any other case, the parameters are taken as iterators, and the content is initialized with the values of the elements that go from the element referred by iterator begin to the element right before the one referred by iterator end. So what does that mean if InputIterator is a char * ?

    Read the article

  • About the String#substring() method

    - by alain.janinm
    If we take a look at the String#substring method implementation : new String(offset + beginIndex, endIndex - beginIndex, value); We see that a new String is created with the same original content (parameter char [] value). So the workaround is to use new String(toto.substring(...)) to drop the reference to the original char[] value and make it eligible for GC (if no more references exist). I would like to know if there is a special reason that explain this implementation. Why the method doesn't create herself the new shorter String and why she keeps the full original value instead? The other related question is : should we always use new String(...) when dealing with substring?

    Read the article

  • Codesample with bufferoverflow (gets method). Why does it not behave as expected?

    - by citronas
    This an extract from an c program that should demonstrate a bufferoverflow. void foo() { char arr[8]; printf(" enter bla bla bla"); gets(arr); printf(" you entered %s\n", arr); } The question was "How many input chars can a user maximal enter without a creating a buffer overflow" My initial answer was 8, because the char-array is 8 bytes long. Although I was pretty certain my answer was correct, I tried a higher amount of chars, and found that the limit of chars that I can enter, before I get a segmentation fault is 11. (Im running this on A VirtualBox Ubuntu) So my question is: Why is it possible to enter 11 chars into that 8 byte array?

    Read the article

  • Multi-threaded random_r is slower than single threaded version.

    - by Nixuz
    The following program is essentially the same the one described here. When I run and compile the program using two threads (NTHREADS == 2), I get the following run times: real 0m14.120s user 0m25.570s sys 0m0.050s When it is run with just one thread (NTHREADS == 1), I get run times significantly better even though it is only using one core. real 0m4.705s user 0m4.660s sys 0m0.010s My system is dual core, and I know random_r is thread safe and I am pretty sure it is non-blocking. When the same program is run without random_r and a calculation of cosines and sines is used as a replacement, the dual-threaded version runs in about 1/2 the time as expected. #include <pthread.h> #include <stdlib.h> #include <stdio.h> #define NTHREADS 2 #define PRNG_BUFSZ 8 #define ITERATIONS 1000000000 void* thread_run(void* arg) { int r1, i, totalIterations = ITERATIONS / NTHREADS; for (i = 0; i < totalIterations; i++){ random_r((struct random_data*)arg, &r1); } printf("%i\n", r1); } int main(int argc, char** argv) { struct random_data* rand_states = (struct random_data*)calloc(NTHREADS, sizeof(struct random_data)); char* rand_statebufs = (char*)calloc(NTHREADS, PRNG_BUFSZ); pthread_t* thread_ids; int t = 0; thread_ids = (pthread_t*)calloc(NTHREADS, sizeof(pthread_t)); /* create threads */ for (t = 0; t < NTHREADS; t++) { initstate_r(random(), &rand_statebufs[t], PRNG_BUFSZ, &rand_states[t]); pthread_create(&thread_ids[t], NULL, &thread_run, &rand_states[t]); } for (t = 0; t < NTHREADS; t++) { pthread_join(thread_ids[t], NULL); } free(thread_ids); free(rand_states); free(rand_statebufs); } I am confused why when generating random numbers the two threaded version performs much worse than the single threaded version, considering random_r is meant to be used in multi-threaded applications.

    Read the article

  • C++: Can a macro expand "abc" into 'a', 'b', 'c'?

    - by Peter Alexander
    I've written a variadic template that accepts a variable number of char parameters, i.e. template <char... Chars> struct Foo; I was just wondering if there were any macro tricks that would allow me to instantiate this with syntax similar to the following: Foo<"abc"> or Foo<SOME_MACRO("abc")> or Foo<SOME_MACRO(abc)> etc. Basically, anything that stops you from having to write the characters individually, like so Foo<'a', 'b', 'c'> This isn't a big issue for me as it's just for a toy program, but I thought I'd ask anyway.

    Read the article

  • Is concatenating with an empty string to do a string conversion really that bad?

    - by polygenelubricants
    Let's say I have two char variables, and later on I want to concatenate them into a string. This is how I would do it: char c1, c2; // ... String s = "" + c1 + c2; I've seen people who say that the "" + "trick" is "ugly", etc, and that you should use String.valueOf or Character.toString instead. I prefer this construct because: I prefer using language feature instead of API call if possible In general, isn't the language usually more stable than the API? If language feature only hides API call, then even stronger reason to prefer it! More abstract! Hiding is good! I like that the c1 and c2 are visually on the same level String.valueOf(c1) + c2 suggests something is special about c1 It's shorter. Is there really a good argument why String.valueOf or Character.toString is preferrable to "" +? Trivia: in java.lang.AssertionError, the following line appears 7 times, each with a different type: this("" + detailMessage);

    Read the article

  • Using sscanf to parse two strings out

    - by Jessica
    I have a semi xml formatted file that contains line with the following format: <param name="Distance" value="1000Km" /> The first char in the string is usually a TAB or spaces. I've been using the following to try to parse the two strings out (from name and value): if(sscanf(lineread, "\t<param name=\"%s\" value=\"%s\" />", name, value) == 1) { //do something } name and value are char* Now, the result is always the same: name gets parse (I need to remove the quotes) and name is always empty. What am I doing wrong? Thanks, code is appreciated. Jess.

    Read the article

  • Internal class and access to external members.

    - by Knowing me knowing you
    I have question with this same title here but now as I'll present in code below this seems to behave in the opposite way to the way explained to me in my first question with the same title. Ok code: class LINT_rep { private: char* my_data_; //stores separately every single digit from a number public: class Iterator:public iterator<bidirectional_operator_tag,char*> { Iterator(const LINT_rep&); }; }; #include "StdAfx.h" #include "LINT_rep.h" LINT_rep::Iterator::Iterator(const LINT_rep& owner):myData_(nullptr) { myData_ = owner.my_data_; /* HERE I'M ACCESSING my_data WHICH IS PRIVATE AND THIS CODE COMPILES ON VS2010 ULTIMATE BUT IT SHOULDN'T BECAUSE my_data IS PRIVATE AND OTHER CLASS SHOULDN'T HAVE ACCESS TO IT'S PRIVATE MEMB. AS EXPLAINED TO ME IN QUESTION TO WHICH I;VE PROVIDED LINK. */ } Question in the code. Thanks.

    Read the article

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