Search Results

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

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

  • Sort an array via x86 Assembly (embedded in C++)?? Possible??

    - by Mark V.
    I am playing around with x86 assembly for the first time and I can't figure out how to sort an array (via insertion sort).. I understand the algorithm, but assembly is confusing me as I primarily use Java & C++. Heres all I have so far int ascending_sort( char arrayOfLetters[], int arraySize ) { char temp; __asm{ push eax push ebx push ecx push edx push esi push edi //// ??? pop edi pop esi pop edx pop ecx pop ebx pop eax } } Basically nothing :( Any ideas?? Thanks in advance.

    Read the article

  • How can I remove the head of a main function?

    - by Nathan McDavitt-Van Fleet
    I am trying to move some code from a seperate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function. How can I create argc and argv by hand? Can someone give me some example assignments. since it looks like this: int main(int argc, char *argv[]) I figured I could assign them like this: int argc=1; char *argv[0]="Example"; But it doesn't work. Can anyone tell me how this might be done?

    Read the article

  • How do you detach an array of strings from shared memory? C

    - by Tim
    I have: int array_id; char* records[10]; // get the shared segment if ((array_id = shmget(IPC_PRIVATE, 1, 0666)) == -1) { perror("Array Creating"); } // attach records[0] = (char*) shmat(array_id, (void*)0, 0); if ((int) *records == -1) { perror("Array Attachment"); } which works fine, but when i try and detach i get an "invalid argument" error. // detach int error; if( (error = shmdt((void*) records[0])) == -1) { perror(array detachment); } any ideas? thank you

    Read the article

  • Use C function in C++ program; "multiply-defined" error

    - by eom
    I am trying to use this code for the Porter stemming algorithm in a C++ program I've already written. I followed the instructions near the end of the file for using the code as a separate module. I created a file, stem.c, that ends after the definition and has extern int stem(char * p, int i, int j) ... It worked fine in Xcode but it does not work for me on Unix with gcc 4.1.1--strange because usually I have no problem moving between the two. I get the error ld: fatal: symbol `stem(char*, int, int)' is multiply-defined: (file /var/tmp//ccrWWlnb.o type=FUNC; file /var/tmp//cc6rUXka.o type=FUNC); ld: fatal: File processing errors. No output written to cluster I've looked online and it seems like there are many things I could have wrong, but I'm not sure what combination of a header file, extern "C", etc. would work.

    Read the article

  • Referencing invalid memory locations with C++ Iterators

    - by themoondothshine
    I am a big fan of GCC, but recently I noticed a vague anomaly. Using __gnu_cxx::__normal_iterator (ie, the most common iterator type used in libstdc++, the C++ STL) it is possible to refer to an arbitrary memory location and even change its value without causing an exception! Is this expected behavior? If so, isn't a security loophole? Here's an example: #include <iostream> using namespace std; int main() { basic_string<char> str("Hello world!"); basic_string<char>::iterator iter = str.end(); iter += str.capacity() + 99999; *iter = 'x'; cout << "Value: " << *iter << endl; }

    Read the article

  • matlab: putting a circled number onto a graph

    - by Jason S
    I want to put a circled number on a graph as a marker near (but not on) a point. Sounds easy, but I also want to be invariant of zoom/aspect ratio changes. Because of this invariant, I can't draw a circle as a line object (without redrawing it upon rescale); if I use a circle marker, I'd have to adjust its offset upon rescale. The simplest approach I can think of is to use the Unicode or Wingdings characters ① ② ③ etc. in a string for the text() function. But unicode doesn't seem to work right, and the following sample only works with ① and not for the other numbers (which yield rectangle boxes): works: clf; text(0.5,0.5,char(129),'FontName','WingDings') doesn't work (should be a circled 2): clf; text(0.5,0.5,char(130),'FontName','WingDings') What gives, and can anyone suggest a workaround?

    Read the article

  • Perl : How to print all cp1252 characters on by one ?

    - by Vinay
    Hi,i am not able to write a script to print all the latin -1 characters one by one.Can anybody help me in solving the problem? I am using the below code but it is not giving me expected result. foreach $char(0..255) { $hexval = sprintf("%x",$char); $charval = sprintf("%c",%hexval); print "$charval"; } output should be like :- 0065 - e 0066 - f ... ... 007F - character at the step For all the codepoints after 007F,it is not giving me expected results. Please help me out with this

    Read the article

  • How to remove [^a-z\s] in C++

    - by Steven
    So far I have: int SimplifyText(char chars[], int length) { //To lower for(int i=0; i<length; i++) { chars[i] = tolower(chars[i]); } This function simplifies the text in the first argument which is an array containing the number of characters as given in the second argument The requirements are: tolower all remove all non-alpha characters replace multiple whitespace by one blank. Any leading whitespace at the beginning of the array should be removed completely. The resulting number of characters should be returned as the value of the function. And the annoying part: Another array cannot appear in the function Cannot use strings, only char arrays. Cannot using G++'s extension for setting an array size using a variable. Oh and can't use regex :) I'm stuck with this, any help would be great. :)

    Read the article

  • Flex, continuous scanning stream (from socket). Did I miss something using yywrap()?

    - by Diederich Kroeske
    Working on a socketbased scanner (continuous stream) using Flex for pattern recognition. Flex doesn't find a match that overlaps 'array bounderies'. So I implemented yywrap() to setup new array content as soon yylex() detects < (it will call yywrap). No success so far. Basically (for pin-pointing my problem) this is my code: %{ #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUFFERSIZE 26 /* 0123456789012345678901234 */ char cbuf1[BUFFERSIZE] = "Hello everybody, lex is su"; // Warning, no '\0' char cbuf2[BUFFERSIZE] = "per cool. Thanks! "; char recvBuffer[BUFFERSIZE]; int packetCnt = 0; YY_BUFFER_STATE bufferState1, bufferState2; %} %option nounput %option noinput %% "super" { ECHO; } . { printf( "%c", yytext[0] );} %% int yywrap() { int retval = 1; printf(">> yywrap()\n"); if( packetCnt <= 0 ) // Stop after 2 { // Copy cbuf2 into recvBuffer memcpy(recvBuffer, cbuf2, BUFFERSIZE); // yyrestart(NULL); // ?? has no effect // Feed new data to flex bufferState2 = yy_scan_bytes(recvBuffer, BUFFERSIZE); // packetCnt++; // Tell flex to resume scanning retval = 0; } return(retval); } int main(void) { printf("Lenght: %d\n", (int)sizeof(recvBuffer)) ; // Copy cbuf1 into recvBuffer memcpy(recvBuffer, cbuf1, BUFFERSIZE); // packetCnt = 0; // bufferState1 = yy_scan_bytes(recvBuffer, BUFFERSIZE); // yylex(); yy_delete_buffer(bufferState1); yy_delete_buffer(bufferState2); return 0; } This is my output: dkmbpro:test dkroeske$ ./text Lenght: 26 Hello everybody, lex is su>> yywrap() per cool. Thanks! >> yywrap() So no match on 'super'. According to the doc the lexxer is not 'reset' between yywrap's. What do I miss? Thanks.

    Read the article

  • Sending while receiving in C

    - by Spidfire
    I've made a piece of code in what's on my server, the problem is that it doesn't send while im receiving. so if i send something to client 1 to client 2, client2 only receives if he sends something himself.. how can i solve this ? /* Thread*/ while (! stop_received) { nr_bytes_recv = recv(s, buffer, BUFFSIZE, 0); if(strncmp(buffer, "SEND", 4) == 0) { char *message = "Text asads \n"; rv = send(users[0].s, message, strlen(message), 0); rv = send(users[1].s, message, strlen(message), 0); if (rv < 0) { perror("Error sending"); exit(EXIT_FAILURE); } }else{ char *message = "Unknown command \n"; rv = send(s, message, strlen(message), 0); if (rv < 0) { perror("Error sending"); exit(EXIT_FAILURE); } } }

    Read the article

  • zeroing out memory

    - by robUK
    Hello, gcc 4.4.4 c89 I am just wondering what most c programmers do when they want to zero out memory. For example I have a buffer of 1024 bytes. Sometimes I do this: char buffer[1024] = {0}; Which will zero all bytes. However, should I declare like this and use memset? char buffer[1024]; . . memset(buffer, 0, sizeof(buffer); Is there any real reason you have to zero the memory? What is the worst that can happen by not doing it? Many thanks for any suggestions,

    Read the article

  • c++ template function compiles in header but not implementation

    - by flies
    I'm trying to learn templates and I've run into this confounding error. I'm declaring some functions in a header file and I want to make a separate implementation file where the functions will be defined. Here's the code that calls the header (dum.cpp): #include <iostream> #include <vector> #include <string> #include "dumper2.h" int main() { std::vector<int> v; for (int i=0; i<10; i++) { v.push_back(i); } test(); std::string s = ", "; dumpVector(v,s); } now, here's a working header file (dumper2.h): #include <iostream> #include <string> #include <vector> void test(); template <class T> void dumpVector( std::vector<T> v,std::string sep); template <class T> void dumpVector(std::vector<T> v, std::string sep) { typename std::vector<T>::iterator vi; vi = v.begin(); std::cout << *vi; vi++; for (;vi<v.end();vi++) { std::cout << sep << *vi ; } std::cout << "\n"; return; } with implentation (dumper2.cpp): #include <iostream> #include "dumper2.h" void test() { std::cout << "!olleh dlrow\n"; } the weird thing is that if I move the code that defines dumpVector from the .h to the .cpp file, I get the following error: g++ -c dumper2.cpp -Wall -Wno-deprecated g++ dum.cpp -o dum dumper2.o -Wall -Wno-deprecated /tmp/ccKD2e3G.o: In function `main': dum.cpp:(.text+0xce): undefined reference to `void dumpVector<int>(std::vector<int, std::allocator<int> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2: ld returned 1 exit status make: *** [dum] Error 1 So why does it work one way and not the other? Clearly the compiler can find test(), so why can't it find dumpVector?

    Read the article

  • How can I return to a string address and then assign it to a new string?

    - by Y_Y
    I have 1 function that I want to return the address of an assigned string to the main function and assign an new string pointer with the same address so that the new string will have the contents of the old string. For example: unknown_datatype function() { char *old = "THE STRING"; return old; } int main() { char *snew = ""; snew = function(); return 0; } *unknown_datatype means I don't know that to put there... *How can I approach this without changing anything in the main() method

    Read the article

  • Objective-C: how to splt a string constant across multiple lines

    - by Ilya
    Hi, I have a pretty long sqlite query: const char *sql_query = "SELECT statuses.word_id FROM lang1_words, statuses WHERE statuses.word_id = lang1_words.word_id ORDER BY lang1_words.word ASC"; How can I break it in a number of lines to make it easier to read? If I do the following: const char *sql_query = "SELECT word_id FROM table1, table2 WHERE table2.word_id = table1.word_id ORDER BY table1.word ASC"; I am getting a error. Is there a way to write queries in multiple lines? Thank you.

    Read the article

  • How can I declare a pointer with filled information in C++?

    - by chacham15
    typedef struct Pair_s { char *first; char *second; } Pair; Pair pairs[] = { {"foo", "bar"}, //this is fine {"bar", "baz"} }; typedef struct PairOfPairs_s { Pair *first; Pair *second; } PairOfPairs; PairOfPairs pops[] = { {{"foo", "bar"}, {"bar", "baz"}}, //How can i create an equivalent of this NEATLY {&pairs[0], &pairs[1]} //this is not considered neat (imagine trying to read a list of 30 of these) }; How can I achieve the above style declaration semantics?

    Read the article

  • Using sizeof with a dynamically allocated array

    - by robUK
    Hello, gcc 4.4.1 c89 I have the following code snippet: #include <stdlib.h> #include <stdio.h> char *buffer = malloc(10240); /* Check for memory error */ if(!buffer) { fprintf(stderr, "Memory error\n"); return 1; } printf("sizeof(buffer) [ %d ]\n", sizeof(buffer)); However, the sizeof(buffer) always prints 4. I know that a char* is only 4 bytes. However, I have allocated the memory for 10kb. So shouldn't the size be 10240? I am wondering am I thinking right here? Many thanks for any suggestions,

    Read the article

  • explain this macro

    - by deostroll
    #define __T(x) L ## x Found in code from one of the MFC source header file. It is mostly used for converting strings to ........ (I don't know what). If I am correct it converts strings to LPCTSTR...don't know what that type is either... I can't seem to convert char* into LPCTSTR. While MFC file handling, the following code will always return error while trying to open the file... char* filepath = "C:\\Program Files\\Microsoft Office\\Office12\\BITMAPS\\STYLES\\GLOBE.WMF"; if( !file.Open((LPCTSTR)filepath , CFile::modeRead, &fexp) ) { fexp.ReportError(); return 1; } But instead if I wrote it this way, it doesn't give error: if( !file.Open( _T("C:\\Program Files\\Microsoft Office\\Office12\\BITMAPS\\STYLES\\GLOBE.WMF") , CFile::modeRead, &fexp) ) { fexp.ReportError(); return 1; } I am looking at passing a variable as the first argument to the CFile::Open() method.

    Read the article

  • Const-Qualification of Main's Parameters in C++

    - by pt2cv
    The C++ standard mandates that all conforming implementations support the following two signatures for main: int main(); int main(int, char*[]); In case of the latter signature, would the addition of (top-level) const-ness break any language rules? For example: int main(const int argc, char** const argv); From my understanding, top-level const qualification doesn't affect the function's signature hash, so it should be legal as far as the specification is concerned. Also, did anyone ever encounter an implementation which rejected this type of modification?

    Read the article

  • How to remove an item from a structure array in C++?

    - by Antik
    I have the following array structure (linked list): struct str_pair { char ip [50] ; char uri [50] ; str_pair *next ; } ; str_pair *item; I know to create a new item, I need to use item = new str_pair; However, I need to be able to loop through the array and delete a particular item. I have the looping part sorted. But how do I delete an item from an array of structures?

    Read the article

  • Problems with first argument being string when overloading the + operator in C++

    - by Chris_45
    I have an selfmade Stringclass: //String.h String & operator = (const String &); String & operator = (char*); const String operator+ (String& s); const String operator+ (char* sA); . . //in main: String s1("hi"); String s2("hello"); str2 = str1 + "ok";//this is ok to do str2 = "ok" + str1;//but not this way //Shouldn't it automatically detect that one argument is a string and in both cases?

    Read the article

  • Read options from file

    - by Devel
    I would like to write a function which will read values from a text file and write them to variables. For example my file is: mysql_server localhost mysql_user root mysql_passworg pospaz mysql_database testgenerator log log.txt username admin password abcd and I have the same variables as the first word in the line. So how to make the function read data from file and do sth like this: char *mysql_server = localhost; char *mysql_user = root; ... I have no idea even how to start writing it...

    Read the article

  • How to check total cache size using a program

    - by user1888541
    so I'm having some trouble creating a program to measure cache size in C. I understand the basic concept of going about this but I'm still having trouble figuring out exactly what I am doing wrong. Basically, I create an array of varying length (going by power of 2s) and access each element in the array and put it in a dummy variable. I go through the array and do this around 1000 times to negate the "noise" that would otherwise occur if I only did it once to get an accurate measurement for time. Then, I look for the size that causes a big jump in access time. Unfortunately, this is where I am having my problem, I don't see this jump using my code and clearly I am doing something wrong. Another thing is that I used /proc/cpuinfo to check the cache and it said the size was 6114 but that was not a power of 2. I was told to go by powers of 2 to figure out the cache can anyone explain why this is? Here is the just of my code...I will post the rest if need be { struct timeval start; struct timeval end; // int n = 1; // change this to test different sizes int array_size = 1048576*n; // I'm trying to check the time "manually" first before creating a loop for the program to do it by itself this is why I have a separate "n" variable to increase the size char x = 0; int i =0, j=0; char *a; a =malloc(sizeof(char) * (array_size)); gettimeofday(&start,NULL); for(i=0; i<1000; i++) { for(j=0; j < array_size; j += 1) { x = a[j]; } } gettimeofday(&end,NULL); int timeTaken = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec *1000000 + start.tv_usec); printf("Time Taken: %d \n", timeTaken); printf("Average: %f \n", (double)timeTaken/((double)array_size); }

    Read the article

  • Set argument pointer to point to new memory inside a function (without returning it) IN C

    - by user321605
    Hello, Hopefully my title was descriptive enough to attract the right help. I want to write a function that will return 1 thing, and modify a provided pointer in another. My current function declaration is . . . char * afterURL replaceURLS(char * body) What I want to do is copy all of body's data into a new string, and set body to point to this new data. I then want afterURL to point to a location within the new string. My issue is getting the actual pointer that is passed in to this function to point to the new data. Thanks in advance! Rob

    Read the article

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