Search Results

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

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

  • C++ STL: Trouble with string iterators

    - by Rosarch
    I'm making a simple command line Hangman game. void Hangman::printStatus() { cout << "Lives remaining: " << livesRemaining << endl; cout << getFormattedAnswer() << endl; } string Hangman::getFormattedAnswer() { return getFormattedAnswerFrom(correctAnswer.begin(), correctAnswer.end()); } string Hangman::getFormattedAnswerFrom(string::const_iterator begin, string::const_iterator end) { return begin == end? "" : displayChar(*begin) + getFormattedAnswerFrom(++begin, end); } char Hangman::displayChar(const char c) { return c; } (Eventually, I'll change this so displayChar() displays a - or a character if the user has guessed it, but for simplicity now I'm just returning everything.) When I build and run this from VS 2010, I get a popup box: Debug Assertion Failed! xstring Line: 78 Expression: string iterator not dereferenceable What am I doing wrong?

    Read the article

  • syntax error : missing ';' before identifier

    - by numerical25
    I am new to c++, trying to debug the following line of code class cGameError { string m_errorText; public: cGameError( char *errorText ) { DP1("***\n*** [ERROR] cGameError thrown! text: [%s]\n***\n", errorText ); m_errorText = string( errorText ); } const char *GetText() { return m_errorText.c_str(); } }; enum eResult { resAllGood = 0, // function passed with flying colors resFalse = 1, // function worked and returns 'false' resFailed = –1, // function failed miserably resNotImpl = –2, // function has not been implemented resForceDWord = 0x7FFFFFFF }; This header file is included in the program as followed #include "string.h" #include "stdafx.h" #include "Chapter 01 MyVersion.h" #include "cGameError.h"

    Read the article

  • C# equivalent of recv?

    - by mlh
    Hello, I have a portion of C code that I am trying to port over to C#. In my C code, I create a socket and then issue a receive command. The receive command is void receive(mysocket, char * command_buffer) { recv(mysocket, command_buffer, COMMAND_BUFFER_SIZE, 0); } now, the command buffer is returned with new values including command_buffer[8] being a pointer to a string. I'm really confused as to how to do this in C# because C# Read() command specifically takes in bytes and not char. The important part is that I get the pointer to the string. Any ideas?

    Read the article

  • extracting string occurrence in c

    - by David78
    I have a string from a text file that look something like this: long_str = "returns between paragraphs 20102/34.23" - 9203 1232 "test" "basic HTML" Note: Quotes are part of the string. int match(char *long_str){ char * str; if ((str = strchr(long_str, '"')) != NULL) str++; // last " ? else return 1; return 0; } Using strstr I'm trying to get the whole substring between the last two quotes: "basic HTML". I'm just not quite sure what would be a good and efficient way of getting that match. I'm open to any other ideas on how to approach this. Thanks

    Read the article

  • define macro in C wont work

    - by Spidfire
    Im trying to make a macro in C that can tell if a char is a hex number ( 0-9 a-z A-Z) #define _hex(x) (((x) >= "0" && (x) <= "9" )||( (x) >= "a" && (x) <= "z") || ((x) >= "A" && (x) <= "Z") ? "true" : "false") this what ive come up with but it wont work with a loop like this char a; for(a = "a" ; a < "z";a++){ printf("%s => %s",a, _hex(a)); } but it gives a error test.c:8: warning: assignment makes integer from pointer without a cast test.c:8: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer test.c:9: warning: comparison between pointer and integer

    Read the article

  • Reading from a file into an array in c

    - by NaNa21
    My file contains a series of numbers (integer, float, integer, float ....), each written on a separate line. The numbers of columns are different from one line to another i.e. 1 2.45 3 1.75 5 3.45 7 2.55 9 3.25 6 1.75 4 3.55 6 2.55 9 2.45 The program should read the contents of the entire file and place the data into an array of type float with an entry for each line. Here is my basic solution, but this is only suitable if I have fixed no of columns. float Read(FILE *pFile) { char line[50]; char letter[5]; fi = fopen("file.txt", "r"); while (fgets(line,200,fi)!=NULL) { sscanf(line,"%f %f %f",&a[i], &a2[i],&a3[i]); printf("%2.0f %2.5f %2.0f\n",a[i],a2[i],a3[i]); } fclose(fi); return a[i]; } Please HELP.

    Read the article

  • Redundant naming in C/C++ typedefs/structs

    - by bloomy
    #include <stdio.h> #include <string.h> const int NAMELEN=30; const int MAXCLASSSIZE=10; typedef struct StudentRec { char lastname[NAMELEN]; char firstname[NAMELEN]; long int ID; int finalmark; }Student; I'm new to coding..and I have a question about why there is Student; after the bracket.. is it a format that we have to follow.

    Read the article

  • Sending a file from memory (rather than disk) over HTTP using libcurl

    - by cinek1lol
    Hi! I would like to send pictures via a program written in C + +. - OK WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL); It works, but I would like to send the pictures from pre-loaded carrier to a variable char (you know what I mean? First off, I load the pictures into a variable and then send the variable), cause now I have to specify the path of the picture on a disk. I wanted to write this program in c++ by using the curl library, not through exe. extension. I have also found such a program (which has been modified by me a bit) #include <stdio.h> #include <string.h> #include <iostream> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "send", CURLFORM_FILE, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "nowy.jpg", CURLFORM_COPYCONTENTS, "nowy.jpg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php"); if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) ) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all (headerlist); } system("pause"); return 0; }

    Read the article

  • Getting MATLAB variable (string) from C

    - by Hamming
    Hi! I'm writing a small C application that launchs a Matlab script (.m file). I need to exchange some variables and I don't know how to get an array of chars that exists in Matlab. I'm doing something like this: enter code here result = engGetVariable(ep,"X"); if (!result) { printf ("Error..."); exit -1; } int n = mxGetN(result); char *varx = NULL; memcpy(varx, mxGetData(result),n*sizeof(char)); It doesn't work. Does someone know how to get a Matlab string in C? I've read Matlab documentation about engGetVariable() and the provided example but any of this things clarify me.

    Read the article

  • Sqlite insertion problem

    - by Devi
    Hi, I had sqlite database for my application I am able to retrieve values from my sqlite table and inserting values with no sql error but unable to find in sqlite table....please do needful help for this problem. I just stucked up at this point plz help me here is my code NSMutableString *registrationquery=[NSMutableString stringWithFormat:@"insert into tbl_kicks values ('%@','%@','%@')",[totalkicks text],[sessionstart text],[sessionstart text],@"0"]; //NSString *sqlNSString = [NSString stringWithFormat:@"INSERT INTO 'tbl_kicks' VALUES('%d','%@','%@');", // 4,sessionstart.text, appDelegate.note]; const char *sqlString = [registrationquery UTF8String]; char *sqlError; sqlite3_exec( appDelegate.database, sqlString, NULL, NULL, &sqlError );

    Read the article

  • Different sizes of same strings - Telnet programming

    - by tommyogp
    Hi all, I have been trying to create an iphone app sending telnet command. However what puzzling me is that the sizes of certain strings are so much different, particularly when they include \n or \r. I listed out a few examples. Please assist. const char *a = "play 25\n"; int sizeBitA1 = sizeof(a); // 8 units int sizeBitA2 = sizeof("play 25\n"); // 9 units const char *b = "\r\n"; int sizeBitB1 = sizeof(b); // 8 units int sizeBitB2 = sizeof("\r\n"); // 3 units

    Read the article

  • how to create multiple tcp connections between server and client

    - by lowcosthighperformance
    I am new in Unix/Linux networking programming, so I have written server-client program in below.In this code there is one socket between client and server, client requests to server, then server responses from 1 to 100 numbers to client. So my question is how can we do this process with 3 socket( tcp connection) without using thread? ( e.g. First socket runs then second runs then third runs then first again .. ) Do you have any suggestion? Thank you client.c int main() { int sock; struct sockaddr_in sa; int ret; char buf[1024]; int x; sock = socket (AF_INET, SOCK_STREAM, 0); bzero (&sa, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(SERVER_PORT); inet_pton (AF_INET, SERVER_IP, &sa.sin_addr); ret = connect (sock, (const struct sockaddr *) &sa,sizeof (sa)); if (ret != 0) { printf ("connect failed\n"); exit (0); } x = 0; while (x != -1) { read (sock, buf , sizeof(int)); x = ntohl(*((int *)buf)); if (x != -1) printf ("int rcvd = %d\n", x); } close (sock); exit (0); } server.c int main() { int list_sock; int conn_sock; struct sockaddr_in sa, ca; socklen_t ca_len; char buf[1024]; int i; char ipaddrstr[IPSTRLEN]; list_sock = socket (AF_INET, SOCK_STREAM, 0); bzero (&sa, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_ANY); sa.sin_port = htons(SERVER_PORT); bind (list_sock,(struct sockaddr *) &sa,sizeof(sa)); listen (list_sock, 5); while (1){ bzero (&ca, sizeof(ca)); ca_len = sizeof(ca); // important to initialize conn_sock = accept (list_sock,(struct sockaddr *) &ca,&ca_len); printf ("connection from: ip=%s port=%d \n",inet_ntop(AF_INET, &(ca.sin_addr), ipaddrstr, IPSTRLEN),ntohs(ca.sin_port)); for (i=0; i<100; ++i){ *((int *)buf) = htonl(i+20); // we using converting to network byte order write (conn_sock, buf, sizeof(int)); } * ((int *)buf) = htonl(-1); write (conn_sock, buf, sizeof(int)); close (conn_sock); printf ("server closed connection to client\n"); } }

    Read the article

  • Writing a C++ wrapper for a C library

    - by stripes
    I have a legacy C library, written in an OO type form. Typical functions are like: LIB *lib_new(); void lib_free(LIB *lib); int lib_add_option(LIB *lib, int flags); void lib_change_name(LIB *lib, char *name); I'd like to use this library in my C++ program, so I'm thinking a C++ wrapper is required. The above would all seem to map to something like: class LIB { public: LIB(); ~LIB(); int add_option(int flags); void change_name(char *name); ... }; I've never written a C++ wrapper round C before, and can't find much advice about it. Is this a good/typical/sensible approach to creating a C++/C wrapper?

    Read the article

  • What is wrong with my version of strchr?

    - by Eduard Saakashvili
    My assignment is to write my own version of strchr, yet it doesn't seem to work. Any advice would be much appreciated. Here it is: char *strchr (const char *s, int c) //we are looking for c on the string s { int dog; //This is the index on the string, initialized as 0 dog = 0; int point; //this is the pointer to the location given by the index point = &s[dog]; while ((s[dog] != c) && (s[dog] != '\0')) { //it keeps adding to dog until it stumbles upon either c or '\0' dog++; } if (s[dog]==c) { return point; //at this point, if this value is equal to c it returns the pointer to that location } else { return NULL; //if not, this means that c is not on the string } }

    Read the article

  • comlen function in Java

    - by davit-datuashvili
    in c or c++ the function comlen is defined such int comlen(char *p,char *q){ int i=0; while *p && (*p++==*q++) i++; return i; } Is this code equivalent of this function? int comlen(String s,String m){ int i=0; while (i<s.length() && s.charAt(i)==m.charAt(i)){ i++; } return i; }

    Read the article

  • array of objects of a class

    - by anurag18294
    #include class test{ int a; char b; public: test() { cout<<"\n\nDefault constructor being called"; } test(int i,char j) { a=i; b=j; cout<<"\n\nConstructor with arguments called"; } }; int main() { test tarray[5]; test newobj(31,'z'); }; In the above code snippet can we intialize values to tarray[5].

    Read the article

  • C++ how to store integer into a binary file??

    - by blaxc
    i gt a struct with 2 integer, i want to store them in a binary file and read it again... here is my code... struct pw { int a; int b; }; void main(){ pw* p = new pw(); pw* q = new pw(); std::ofstream fout(ADMIN_FILE, ios_base::out | ios_base::binary | ios_base::trunc); std::ifstream fin(ADMIN_FILE, ios_base::in | ios_base::binary); p->a=123; p->b=321; fout.write((const char*)p, sizeof(pw)); fin.write((char*)q, sizeof(pw)); fin.close(); cout<< q->a << endl;} my output is 0. anyone can tell me what is the problem?

    Read the article

  • Encryption By Certificate

    - by user1817240
    I am encrypting customer name in database at database level. While saving in database only first letter of customer name is saved and hence while decrypting only first letter is retrieved. The following code shows the test sp. ALTER PROCEDURE [dbo].[spc_test_insert] ( @sFIRST_NAME typ_encryptedtext, ) AS BEGIN DECLARE @sSENCRYPTION_KEY char(15) DECLARE @sCERTIFICATE char(22) SET @sSENCRYPTION_KEY='SymmetricKey1' SET @sCERTIFICATE='CustomerCertificate' OPEN SYMMETRIC KEY SymmetricKey1 DECRYPTION BY CERTIFICATE CustomerCertificate; INSERT INTO test_table ( FIRST_NAME, ) Values ( -- Add the Params to be Added... EncryptByKey(Key_GUID(@sSENCRYPTION_KEY),@sFIRST_NAME), ) CLOSE SYMMETRIC KEY SymmetricKey1 END encryption decryption working fine in normal insert but its not working in stored procedure.

    Read the article

  • hash table with chaining method program freezing

    - by Justin Carrey
    I am implementing hash table in C using linked list chaining method. The program compiles but when inserting a string in hash table, the program freezes and gets stuck. The program is below: struct llist{ char *s; struct llist *next; }; struct llist *a[100]; void hinsert(char *str){ int strint, hashinp; strint = 0; hashinp = 0; while(*str){ strint = strint+(*str); } hashinp = (strint%100); if(a[hashinp] == NULL){ struct llist *node; node = (struct llist *)malloc(sizeof(struct llist)); node->s = str; node->next = NULL; a[hashinp] = node; } else{ struct llist *node, *ptr; node = (struct llist *)malloc(sizeof(struct llist)); node->s = str; node->next = NULL; ptr = a[hashinp]; while(ptr->next != NULL){ ptr = ptr->next; } ptr->next = node; } } void hsearch(char *strsrch){ int strint1, hashinp1; strint1 = 0; hashinp1 = 0; while(*strsrch){ strint1 = strint1+(*strsrch); } hashinp1 = (strint1%100); struct llist *ptr1; ptr1 = a[hashinp1]; while(ptr1 != NULL){ if(ptr1->s == strsrch){ cout << "Element Found\n"; break; } else{ ptr1 = ptr1->next; } } if(ptr1 == NULL){ cout << "Element Not Found\n"; } } hinsert() is to insert elements into hash and hsearch is to search an element in the hash. Hash function is written inside hinsert() itself. In the main(), what i am initializing all the elements in a[] to be NULL like this: for(int i = 0;i < 100; i++){ a[i] = NULL; } Help is very much appreciated. Thanks !

    Read the article

  • Set intersection of two strings

    - by user1785712
    import java.util.*; class set { public static void main(String args[]) { TreeSet<Character> t1 = new TreeSet<Character>(); TreeSet<Character> t2 = new TreeSet<Character>(); String s1 = "Ambitab bachan"; String s2 = "Ranjikanth"; for(char c1:s1.toCharArray()) t1.add(c1); for(char c2:s2.toCharArray()) t2.add(c2); t2.retainAll(t1); System.out.println(t2); } } this program find the common character in two different string. in this program Treeset is used to store the value and retainAll() method is used to find the common characters. can anybody help me reduce the line of coding.thanks in advance

    Read the article

  • use printf("text %d", number) type format to assign value to variable

    - by rksprst
    I would like to use the syntax that printf uses, using the %d, %s and adding values after to assign a value to a char[]. Is this possible? e.g. Given an output of: printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); I'd like to assign that to char[] output; How can this be done? I tried: sprintf(output, "now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); but that didn't seem to work. Is sprintf used differently... or is that not what I should be using? Thanks!

    Read the article

  • Any idea why this query always returns duplicate items?

    - by Kardo
    I want to get all Images not used by current ItemID. The this subquery but it also always returns duplicate Images: EDITED select Images.ImageID, Images.ItemStatus, Images.UserName, Images.Url, Image_Item.ItemID, Image_Item.ItemID from Images left join (select ImageID, ItemID, MAX(DateCreated) x from Image_Item where ItemID != '5a0077fe-cf86-434d-9f3b-7ff3030a1b6e' group by ImageID, ItemID having count(*) = 1) image_item on Images.imageid = image_item.imageid where ItemID is not null I guess the problem is with the subquery which I can't avoid duplicate rows: select ImageID, ItemID, MAX(DateCreated) x from Image_Item where ItemID != '5a0077fe-cf86-434d-9f3b-7ff3030a1b6e' group by ImageID, ItemID having count(*) = 1 Result: F2EECBDC-963D-42A7-90B1-4F82F89A64C7 0578AC61-3C32-4A1D-812C-60A09A661E71 F2EECBDC-963D-42A7-90B1-4F82F89A64C7 9A4EC913-5AD6-4F9E-AF6D-CF4455D81C10 42BC8B1A-7430-4915-9CDA-C907CBC76D6A CB298EB9-A105-4797-985E-A370013B684F 16371C34-B861-477C-9A7C-DEB27C8F333D 44E6349B-7EBF-4C7E-B3B0-1C6E2F19992C Table: Images ImageID uniqueidentifier UserName nvarchar(100) DateCreated smalldatetime Url nvarchar(250) ItemStatus char(1) Table: Image_Item ImageID uniqueidentifier ItemID uniqueidentifier UserName nvarchar(100) ItemStatus char(1) DateCreated smalldatetime Any kind help is highly appreciated.

    Read the article

  • Adding characters to string

    - by Jamza
    I am currently trying to build a very basic serial shell with my arduino. I am able to get an output from the device using Serial.read() and can get the character it has outputted, but I cannot work out how to then add that character to a longer to form the full command. I tried the logical thing but it doesn't work: char Command[]; void loop(){ if(Serial.available() > 0){ int clinput = Serial.read(); Command = Command + char(clinput); } Can anybody help? Thank You.

    Read the article

  • C++ convert formatted string to a stream

    - by Roey
    Hi All, I'm using VS2008 C++. As I understand it there is no way to pass something like this in a C++ stream : (without using external libraries) "number " << i <------ when i is an integer. So I was looking for a better way to do this, and I all I could come up with is create a string using : char fullstring = new char[10]; sprintf(fullString, "number %d", i); .... pass fullstring to the stream ..... delete[] fullString; I know it's stupid, but is there a better way of doing this?

    Read the article

  • Program quits if pipe is closed

    - by givemelight
    I am trying to write to a pipe using C++. The following code gets called in an extra thread: void writeToPipe() { int outfifo; char buf[100]; char outfile[] = "out"; mknod(outfile, S_IFIFO | 0666, 0); if ((outfifo = open(outfile, O_WRONLY)) < 0) { perror("Opening output fifo failed"); return false; } int currentTimestamp = (int)time(0); int bufLen = sprintf(bug, "Time is %d.", currentTimestamp); write(outfifo, buf, bufLen); } The thread is called in main using: thread writeThread(writeToPipe); writeThread.detach(); If the pipe is not opened by another process, the C++ program just quits without an error. I don't know how to check if the pipe is opened.

    Read the article

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