Search Results

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

Page 58/245 | < Previous Page | 54 55 56 57 58 59 60 61 62 63 64 65  | Next Page >

  • Getting a character and printing it in VC++

    - by sss123
    I have a problem getting a character from the user in VC++.the function i want to use uses the char format so when i get the input using getch() it gives me an error that can't convert 'int' to 'char'. could someone please help me how to get the input in char format please?

    Read the article

  • Without LIB And String file how can i write this code??

    - by muhammadlodhi
    #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> struct Node; typedef struct Node * PtrToNode; struct Node { char element; PtrToNode Next; }; PtrToNode MakeEmpty(PtrToNode L) { L= new(Node); L->Next=NULL; return L; } void Push(PtrToNode L,char x) { PtrToNode S; S= new(Node); S->element=x; S->Next=L->Next; L->Next=S; } char Pop(PtrToNode L) { PtrToNode P; P=L->Next; char x=P->element; L->Next=P->Next; free(P); return x; } int main() { PtrToNode L; L= MakeEmpty(NULL); char Input[1000]; int i; printf("please enter your equation:"); scanf("%s",Input); for (i = 0;i<strlen(Input);i++) { if (Input[i]=='(') { Push(L,Input[i]); } if (Input[i]==')') { if (L->Next==NULL) { printf("incorrect"); return 0; } else Pop(L); } } if (L->Next==NULL) printf("correct"); else printf("incorrect"); getch(); return 0; }

    Read the article

  • Errors with parameter datatype in PostgreSql query

    - by John
    Im trying to execute a query to postgresql using the following code. It's written in C/C++ and I keep getting the following error when declaring a cursor: DECLARE CURSOR failed: ERROR: could not determine data type of parameter $1 Searching on here and on google, I can't find a solution. Can anyone find where I have made and error and why this is happening? thanks! void searchdb( PGconn *conn, char* name, char* offset ) { // Will hold the number of field in table int nFields; // Start a transaction block PGresult *res = PQexec(conn, "BEGIN"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { printf("BEGIN command failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } // Clear result PQclear(res); printf("BEGIN command - OK\n"); //set the values to use const char *values[3] = {(char*)name, (char*)RESULTS_LIMIT, (char*)offset}; //calculate the lengths of each of the values int lengths[3] = {strlen((char*)name), sizeof(RESULTS_LIMIT), sizeof(offset)}; //state which parameters are binary int binary[3] = {0, 0, 1}; res = PQexecParams(conn, "DECLARE emprec CURSOR for SELECT name, id, 'Events' as source FROM events_basic WHERE name LIKE '$1::varchar%' UNION ALL " " SELECT name, fsq_id, 'Venues' as source FROM venues_cache WHERE name LIKE '$1::varchar%' UNION ALL " " SELECT name, geo_id, 'Cities' as source FROM static_cities WHERE name LIKE '$1::varchar%' OR FIND_IN_SET('$1::varchar%', alternate_names) != 0 LIMIT $2::int4 OFFSET $3::int4", 3, //number of parameters NULL, //ignore the Oid field values, //values to substitute $1 and $2 lengths, //the lengths, in bytes, of each of the parameter values binary, //whether the values are binary or not 0); //we want the result in text format // Fetch rows from table if (PQresultStatus(res) != PGRES_COMMAND_OK) { printf("DECLARE CURSOR failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } // Clear result PQclear(res); res = PQexec(conn, "FETCH ALL in emprec"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { printf("FETCH ALL failed"); PQclear(res); exit_nicely(conn); } // Get the field name nFields = PQnfields(res); // Prepare the header with table field name printf("\nFetch record:"); printf("\n********************************************************************\n"); for (int i = 0; i < nFields; i++) printf("%-30s", PQfname(res, i)); printf("\n********************************************************************\n"); // Next, print out the record for each row for (int i = 0; i < PQntuples(res); i++) { for (int j = 0; j < nFields; j++) printf("%-30s", PQgetvalue(res, i, j)); printf("\n"); } PQclear(res); // Close the emprec res = PQexec(conn, "CLOSE emprec"); PQclear(res); // End the transaction res = PQexec(conn, "END"); // Clear result PQclear(res); }

    Read the article

  • Templated derived class in CRTP (Curiously Recurring Template Pattern)

    - by Butterwaffle
    Hi, I have a use of the CRTP that doesn't compile with g++ 4.2.1, perhaps because the derived class is itself a template? Does anyone know why this doesn't work or, better yet, how to make it work? Sample code and the compiler error are below. Source: foo.C #include <iostream> using namespace std; template<typename X, typename D> struct foo; template<typename X> struct bar : foo<X,bar<X> > { X evaluate() { return static_cast<X>( 5.3 ); } }; template<typename X> struct baz : foo<X,baz<X> > { X evaluate() { return static_cast<X>( "elk" ); } }; template<typename X, typename D> struct foo : D { X operator() () { return static_cast<D*>(this)->evaluate(); } }; template<typename X, typename D> void print_foo( foo<X,D> xyzzx ) { cout << "Foo is " << xyzzx() << "\n"; } int main() { bar<double> br; baz<const char*> bz; print_foo( br ); print_foo( bz ); return 0; } Compiler errors foo.C: In instantiation of ‘foo<double, bar<double> >’: foo.C:8: instantiated from ‘bar<double>’ foo.C:30: instantiated from here foo.C:18: error: invalid use of incomplete type ‘struct bar<double>’ foo.C:8: error: declaration of ‘struct bar<double>’ foo.C: In instantiation of ‘foo<const char*, baz<const char*> >’: foo.C:13: instantiated from ‘baz<const char*>’ foo.C:31: instantiated from here foo.C:18: error: invalid use of incomplete type ‘struct baz<const char*>’ foo.C:13: error: declaration of ‘struct baz<const char*>’

    Read the article

  • Object allocation in C++

    - by Poiuyt
    char *myfunc() { char *temp = "string"; return temp; } In this piece of code, where does the allocation of the object pointed to by temp happen and what would be its scope? Is this function a valid way to return a char* pointer?

    Read the article

  • Python - Is a dictionary slow to find frequency of each character?

    - by psihodelia
    I am trying to find a frequency of each symbol in any given text using an algorithm of O(n) complexity. My algorithm looks like: s = len(text) P = 1.0/s freqs = {} for char in text: try: freqs[char]+=P except: freqs[char]=P but I doubt that this dictionary-method is fast enough, because it depends on the underlying implementation of the dictionary methods. Is this the fastest method?

    Read the article

  • Using popen() to invoke a shell command?

    - by Anvar
    When running the following code through xcode I get inconsistent behavior. Sometimes it prints the git version correctly, other times it doesn't print anything. The return code from the shell command is always 0 though. Any ideas on why this might be? What am I doing wrong? #define BUFFER_SIZE 256 int main (int argc, const char * argv[]) { FILE *fpipe; char *command="/opt/local/bin/git --version"; char line[BUFFER_SIZE]; if ( !(fpipe = (FILE*)popen(command, "r")) ) { // If fpipe is NULL perror("Problems with pipe"); exit(1); } while ( fgets( line, sizeof(char) * BUFFER_SIZE, fpipe)) { // Inconsistent (happens sometimes) printf("READING LINE"); printf("%s", line); } int status = pclose(fpipe); if (status != 0) { // Never happens printf("Strange error code: %d", status); } return 0; }

    Read the article

  • string reverse without new array

    - by Codeguru
    hi can anybody tell me the error in this? #include<stdio.h> int main() { char a[]="abcdefgh"; int i=0; int n=strlen(a); char *first; char *second; char *c; *first=a[0]; *second=a[7]; for(i=0;i<=n/2;i++) { *c=*first; *first=*second; *second=*c; first++; second--; } for(i=0;i<=7;i++) { printf("%c",a[i]); } }

    Read the article

  • operator[][] C++

    - by bobobobo
    I'd like to overload operator[][] to give internal access to a 2D array of char in C++. Right now I'm only overloading operator[], which goes something like class Object { char ** charMap ; char* operator[]( int row ) { return charMap[row] ; } } ; It works ok.. Is it possible to override operator[][] though?

    Read the article

  • Integer to Character conversion in C

    - by nthrgeek
    Lets us consider this snippet: int s; scanf("%c",&s); Here I have used int, and not char, for variable s, now for using s for character conversion safely I have to make it char again because when scanf reads a character it only overwrites one byte of the variable it is assigning it to, and not all four that int has. For conversion I could use s = (char)s; as the next line, but is it possible to implement the same by subtracting something from s ?

    Read the article

  • between syntax, are there any equal function

    - by gcc
    /* char **mainp=malloc(sizeof(char *)*2); mainp[0]=malloc(sizeof(char)*300); mainp[1]=malloc(sizeof(char )*300); */ *I have some input about propositional calculus *After calculating some math funtion-removing paranthesis-changing"&" with ","-replacing "|" with"," I have >> (1) P,-Q,Q,-R is stored in mainp[0] R,A,P,B,F is stored in mainp[1] *My question is: Between comma , I have want to compare two pointer array. If there is any equal two or more functions(Q,-R is function representation) ,function which you will show me how to write must return int. According to example (1),function will return 1 (I expect like that) /*I have som thought://which function should I have use:*/ in for loop if( strspn(mainp[0][i])==1 ) increment d; continue; or in for loop srtcmp(mainp[0][i],mainp[1]);

    Read the article

  • C code Error: free(): invalid next size (fast):

    - by user1436057
    I got an error from my code, but I'm not sure where to fix it. Here's the explanation of what my code does: I'm writing some code that will read an input file and store each line as an object (char type) in an array. The first line of the input file is a number. This number tells me how many lines that I should read and store in the array. Here's my code: int main(int argc, char *argv[]){ FILE *fp; char **path; int num, i; ... /*after reading the first line and store the number value in num*/ path = malloc(num *sizeof(char)); i=0; while (!feof(fp)) { char buffer[500]; int length = 0; for (ch = fgetc(fp); ch != EOF && ch != '\n'; ch = fgetc(fp)) { buffer[length++] = ch; } if(ch == '\n' && ch!= EOF){ buffer[length] = '\0'; path[i] = malloc(strlen(buffer)+1); strcpy(path[i], buffer); i++; } } ... free(path); } After running the code, I get this *** glibc detected *** free(): invalid next size (fast): I have searched around and know this is malloc/free error, but I don't exactly know to fix it. Any help would be great. Thanks!

    Read the article

  • Scala updating/creating value in a hashmap

    - by user1672739
    I don't understand this with Scala hasmaps: How do I create a value or update one if it does not exist? I am tryng to count the number of characters in a list of Strings. I've tried this code but it doesn't work : def times(chars: List[Char]): List[(Char, Int)] = { val map = new HashMap[Char, Int]() chars.foreach( (c : Char) => { map.update(c, map.get(c) + 1) }) } I understand the returning type isn't correct. But is my foreach loop wrong? Is there a prettier way to write it?

    Read the article

  • assigning a string to another string

    - by user1509676
    Why this code is not running? Why str1 is not assigned to str2 ?? I know i have an option of using strcpy but i wish to know the reason why this is not working?? #include<stdio.h> int main() { char str1[]="hello"; char str2[10]; str2=str1; printf("%s",str2); return 0; } Whereas if I use pointers than it works like here.. #include<stdio.h> int main() ( char *s="good morning"; char *q; q=s; while(*q!='\0') { printf("%c",*q); q++; } return 0; } This works. Now the string has been copied via pointers so why such difference??

    Read the article

  • Template Syntax in C++

    - by Crystal
    I don't understand templates really and was trying to run a simple find the minimum for ints, doubles, chars. First question, why is template<typename T> sometimes used, and other times template<>? Second question, I do not know what I am doing wrong with the following code below: #include <iostream> template <typename T> T minimum(T arg1, T arg2) { return arg1 < arg2 ? arg1 : arg2; } template <typename T> // first I tried template <> instd of above, but wasn't sure the difference T minimum<const char *>(const char *arg1, const char *arg2) { return strcmp(arg1, arg2) ? arg2 : arg1; } int main() { std::cout << minimum<int>(4, 2) << '\n'; std::cout << minimum<double>(2.2, -56.7) << '\n'; std::cout << minimum(2.2, 2) << '\n'; } Compile Errors: error C2768: 'minimum' : illegal use of explicit template arguments error C2783: 'T minimum(const char *,const char *)' : could not deduce template argument for 'T' : see declaration of 'minimum' : error C2782: 'T minimum(T,T)' : template parameter 'T' is ambiguous : see declaration of 'minimum' Third, in getting familiar with separating .h and .cpp files, if I wanted this minimum() function to be a static function of my class, but it was the only function in that class, would I have to have a template class as well? I originally tried doing it that way instead of having it all in one file and I got some compile errors as well that I can't remember right now and was unsure how I would do that. Thanks!

    Read the article

  • array and point problem

    - by bezetek
    Here, I have a bad program. Its outputs confusing me, anyone can tell me why ? #include <stdio.h> #include <stdlib.h> int main() { int i = 0; char *a_result[10]; char *b_result[10]; for (i = 0; i < 10; i++) { char a_array[10]; char *b_array = malloc(10*sizeof(char)); int j = 0; for (j = 0; j < 9; j++) { a_array[j] = 'a' + i; b_array[j] = 'a' + i; } a_array[j] = '\0'; b_array[j] = '\0'; a_result[i] = a_array; b_result[i] = b_array; } for (i = 0; i < 10; i++) printf("a_result: %s b_result: %s\n",a_result[i],b_result[i]); return 0; } I think the a_result and b_result should be the same, but it is not. Here is the output on my computer. a_result: jjjjjjjjj b_result: aaaaaaaaa a_result: jjjjjjjjj b_result: bbbbbbbbb a_result: jjjjjjjjj b_result: ccccccccc a_result: jjjjjjjjj b_result: ddddddddd a_result: jjjjjjjjj b_result: eeeeeeeee a_result: jjjjjjjjj b_result: fffffffff a_result: jjjjjjjjj b_result: ggggggggg a_result: jjjjjjjjj b_result: hhhhhhhhh a_result: jjjjjjjjj b_result: iiiiiiiii a_result: jjjjjjjjj b_result: jjjjjjjjj any explanation about this is appreciate!

    Read the article

  • what's wrong with my one-liner strncpy: while(*s++ = *t++ && n-- > 0);?

    - by pvd
    #include <stdio.h> #define STR_BUF 10000 #define STR_MATCH 7 void mystrncpy(char* s, char* t, int n) { while(*s++ = *t++ && n-- > 0); } int main() { int result; char str_s[STR_BUF] = "not so long test string"; char buf_1[STR_BUF]; mystrncpy(buf_1, str_s, STR_MATCH); printf ("buf_1 (mystrncpy, 7 chars): %s\n", buf_1); return 0; } When I run it, nothing happened ian@ubuntu:~/tmp$ gcc myncpy.c -o myn&&./myn buf_1 (mystrncpy, 7chars):

    Read the article

  • Memory alignment in C

    - by user1758245
    Here is a snippet: #pragma pack(4) struct s1 { char a; long b; }; #pragma pack() #pragma pack(2) struct s2 { char c; struct s1 st1; }; #pragma pack() #pragma pack(2) struct s3 { char a; long b; }; #pragma pack() #pragma pack(4) struct s4 { char c; struct s3 st3; }; #pragma pack() I though sizeof(s4) should be 10 or 12. But it turns out to be 8. I am using Visual C++ 6.0. Could someone tell me why?

    Read the article

  • map with string is broken?[solved]

    - by teritriano
    Yes. I can't see what im doing wrong the map is string, int Here the method bange::function::Add(lua_State *vm){ //userdata, function if (!lua_isfunction(vm, 2)){ cout << "bange: AddFunction: First argument isn't a function." << endl; return false;} void *pfunction = const_cast<void *>(lua_topointer(vm, 2)); char key[32] = {0}; snprintf(key, 32, "%p", pfunction); cout << "Key: " << key << endl; string strkey = key; if (this->functions.find(strkey) != this->functions.end()){ luaL_unref(vm, LUA_REGISTRYINDEX, this->functions[strkey]);} this->functions[strkey] = luaL_ref(vm, LUA_REGISTRYINDEX); return true; Ok, when the code is executed... Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6e6caa9 in std::basic_string<char, std::char_traits<char>, std::allocator<char> > ::compare(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const () from /usr/lib/libstdc++.so.6 Seriously, what's wrong with my code. Thanks for help. Edit 1: Ok, I've done the solution and still fails. I've tried directly insert a string but gives the same error. Let's see, the object is a bange::scene inherited from bange::function. I create the object with lua_newuserdata: bange::scene *scene = static_cast<bange::scene *>(lua_newuserdata(vm, sizeof(bange::scene))); (...) scene = new (scene) bange::scene(width, height, nlayers, vm); I need this for LUA garbage collection. Now the access to bange::function::Add from Lua: static int bangefunction_Add(lua_State *vm){ //userdata, function bange::function *function = reinterpret_cast<bange::function *>(lua_touserdata(vm, 1)); cout &lt&lt "object with bange::function: " &lt&lt function << endl; bool added = function->bange::function::Add(vm); lua_pushboolean(vm, static_cast<int>(added)); return 1; } Userdata is bange::scene stored in Lua. Knowing that userdata is scene, in fact, the object's direction is the same when I've created the scene before. I need the reinterpret_cast, and then call the method. The pointer "this" is still the same direction inside the method. solved I did a small test in the bange::function constructor which works without problems. bange::function::function(){ string test("test"); this->functions["test"] = 2; } I finally noticed that the problem is bange::function *function = reinterpret_cast<bange::function *>(lua_touserdata(vm, 1)); because the object is bange::scene and no bange::function (i admit it, a pointer corruption) and this seems more a code design issue. So this, in a way, is solved. Thanks everybody.

    Read the article

  • How to use strtok in C properly so there is no memory leak?

    - by user246392
    I am somewhat confused by what happens when you call strtok on a char pointer in C. I know that it modifies the contents of the string, so if I call strtok on a variable named 'line', its content will change. Assume I follow the bellow approach: void function myFunc(char* line) { // get a pointer to the original memory block char* garbageLine = line; // Do some work // Call strtok on 'line' multiple times until it returns NULL // Do more work free(garbageLine); } Further assume that 'line' is malloced before it is passed to myFunc. Am I supposed to free the original string after using strtok or does it do the job for us? Also, what happens if 'line' is not malloced and I attempt to use the function above? Is it safer to do the following instead? (Assume the programmer won't call free if he knows the line is not malloced) Invocation char* garbageLine = line; myFunc(line); free(garbageLine); Function definition void function myFunc(char* line) { // Do some work // Call strtok on 'line' multiple times until it returns NULL // Do more work }

    Read the article

  • Storing Formatted Data in C

    - by rangerdanger16
    Im trying to add variables to a C char array. Also I have tried sprintf, but it is causing a few other issues within my program. I am looking to do something like this: char* age = "My age is = " + age; I am planning on sending the char array to a socket using send() Thanks

    Read the article

  • how to use string in va_start?

    - by Newbie
    for some reason, i cant get this working: void examplefunctionname(string str, ...){ ... va_start(ap, str.c_str()); nor do i get this work: void examplefunctionname(string str, ...){ ... int len = str.length(); char *strlol = new char[len+1]; for(int i = 0; i < len; i++){ strlol[i] = str[i]; } strlol[len] = 0; va_start(ap, strlol); but this does: void examplefunctionname(const char *str, ...){ ... va_start(ap, str); could someone show me how i can use string instead of const char * there? its outputting random numbers when i call examplefunctionname("%d %d %d", 1337, 1337, 1337)

    Read the article

  • C - How to manipulate typedef structure pointer?

    - by AbhishekJoshi
    typedef struct { int id; char* first; char* last; }* person; person* people; Hi. How can I use this above, all set globally, to fill people with different "person"s? I am having issues wrapping my head regarding the typedef struct pointer. I am aware pointers are like arrays, but I'm having issues getting this all together... I would like to keep the above code as is as well. Edit 1: char first should be char* first.

    Read the article

  • Driver Max - Updating drivers that are not digitally signed - good or bad?

    - by Paul
    Win7 Home Prem 32-bit I am currently using DriverMax to keep my drivers up to date. Sometimes it suggests that a newer driver is available for download but the driver is not digitally signed. Is it safe to update to an unsigned driver or not? What are the implications of signed vs unsigned drivers? I always create a system restore point before updating any drivers anyway and i know i can rollback a driver.

    Read the article

  • How to marshal int* in C#?

    - by MartyIX
    Hi, I would like to call this method in unmanaged library: void __stdcall GetConstraints( unsigned int* puiMaxWidth, unsigned int* puiMaxHeight, unsigned int* puiMaxBoxes ); My solution: Delegate definition: [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void GetConstraintsDel(UIntPtr puiMaxWidth, UIntPtr puiMaxHeight, UIntPtr puiMaxBoxes); The call of the method: // PLUGIN NAME GetConstraintsDel getConstraints = (GetConstraintsDel)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(GetConstraintsDel)); uint maxWidth, maxHeight, maxBoxes; unsafe { UIntPtr a = new UIntPtr(&maxWidth); UIntPtr b = new UIntPtr(&maxHeight); UIntPtr c = new UIntPtr(&maxBoxes); getConstraints(a, b, c); } It works but I have to allow "unsafe" flag. Is there a solution without unsafe code? Or is this solution ok? I don't quite understand the implications of setting the project with unsafe flag. Thanks for help!

    Read the article

< Previous Page | 54 55 56 57 58 59 60 61 62 63 64 65  | Next Page >