30 Discussion / Question Topics

Remove Filter
Member Avatar for monkey_king

I'm having difficulties understanding and printing the max value of a size_t type. Apparantly the size_t is typedefed to a unsigned long int on my system. Is this safe to assume its the same on all c++ compilers? The 'sizeof' function returns the number of bytes(size char), used to represent …

Member Avatar for idallen
0
1K
Member Avatar for monkey_king

Hi, Can someone elaborate why the following (the if conditional) differs [CODE=c] int main(){ const char *filename = "test.txt"; int ifd; if((ifd=open(filename,O_RDONLY))<3) err(EX_NOINPUT, "%s", filename); fprintf(stderr,"ifd is:%d\n",ifd); off_t bytes_in = lseek(ifd, (off_t)(-4), SEEK_END); return 0; } [/CODE] vs [CODE=c] int main(){ const char *filename = "test.txt"; int ifd; if(ifd=open(filename,O_RDONLY)<3) err(EX_NOINPUT, …

Member Avatar for monkey_king
0
126
Member Avatar for monkey_king

Hi I've found a strange problem on ubuntu64bit, that limits the data you are allowed to allocate on a 64bit platform using the c function 'read()' The following program wont allow to allocate more that 2.1gig memory. [CODE=c++] #include <stdio.h> #include <stdlib.h> #include <err.h> #include <fcntl.h> #include <sysexits.h> #include <unistd.h> …

Member Avatar for monkey_king
0
145
Member Avatar for monkey_king

I've been programmin on and off for some time. But today I saw something I hadnt seen before Some thing like [CODE=c] void error OF((const char *msg)); void gz_compress OF((FILE *in, gzFile out)); #ifdef USE_MMAP int gz_compress_mmap OF((FILE *in, gzFile out)); #endif void gz_uncompress OF((gzFile in, FILE *out)); void file_compress …

Member Avatar for jonsca
0
137
Member Avatar for monkey_king

If I simply just want to tokenize the first element of a string and then output the remainder of the string, how can this be accomplished? thanks [CODE=c] #include <stdio.h> #include <string.h> int main(){ const char* line= "0 firstline"; char* l = strdup(line); printf("beforeToknization:\t%s\n",l); char *tok = strtok(l," "); printf("firstToken:%s\trestOfLine:%s\n",tok,l); …

Member Avatar for jephthah
0
3K
Member Avatar for monkey_king

Hi I got a code that in pseudo dos something like [CODE] ifstream os; while(os.oef()){ os.getline(buffer,length); } [/CODE] If some condition is met, I'd like to be able to jump back to the previous line, such that the next getline will give the line just-read in, at a later time …

Member Avatar for tux4life
0
482
Member Avatar for monkey_king

Hi, given a cstring, I need to extract the digits in it, the digits are prefixed with either a '+' or '-'. Like [CODE] ,.,.,.,+3ACT,.,.,.,.-12,.,.,.,.,.,.,.,actgncgt #OUTPUT 3 12 [/CODE] I've made a working program that does what I want, but it seems overly complicated. Does anyone have an idea if …

Member Avatar for Yrth
0
151
Member Avatar for monkey_king

Hi I'm having a very basic newbie problem, The compiler forces me to do a strdup (because of cons correctness), can I void the extra line in my code, and then I cant seem to update my array after the funciton call [CODE=c++] void fix_name(char *name){ if(name[strlen(name)-1]!='/'){ char *tmp = …

Member Avatar for monkey_king
0
189
Member Avatar for monkey_king

Hi, can anyone tell me why i can't clean up the memory, and maybe a small solution. I'm allocing memory with strdup for each key, but I cant figure out how to erase the key with free. Before anyone starts talking about mixing c++ and c, I know it's generally …

Member Avatar for ArkM
0
2K
Member Avatar for monkey_king

Hi, [LIST=1] [*]Question Why does valgrind complain? [CODE] Conditional jump or move depends on uninitialised value(s) ==25636== at 0x4C26D29: strlen (mc_replace_strmem.c:242) ==25636== by 0x40060A: main (test.c:7) [/CODE] [*]Question Strlen doesnt apparantly tell you how much space you have in your array, but the number of chars til '\0'. I my …

Member Avatar for fpmurphy
0
245
Member Avatar for monkey_king

Hi I stumpled upon some c-code, which syntactically is different from what I've seen before. [LIST=1] [*]first [CODE=c] void strreverse(char* begin, char* end) { char aux; while(end>begin) aux=*end, *end--=*begin, *begin++=aux; } [/CODE] Would this be the same as [CODE=c] void strreverse(char* begin, char* end) { char aux; while(end>begin){ aux=*end; *end--=*begin; …

Member Avatar for monkey_king
0
217
Member Avatar for monkey_king

I'm trying to get myself acquainted with memory allocation and deallocation while writing a program that will actually be usefull for me. The program is a simple datareader, that tries to read a matrix from file. The "main" program which works is 'int get_lex(char *in,char *delims,char ***returnvals)' This will essential …

Member Avatar for monkey_king
0
131
Member Avatar for monkey_king

Hi, I'm considering using some boost stuff for my next project. But it's quite essential, that the program can be ported to multiple platforms with different setups. I've always used -ansi -pedantic -Wall And so far the projects has been working on sun/gnu/intel compilers, on both windows and linux. But …

Member Avatar for monkey_king
0
94
Member Avatar for monkey_king

I'm having troubles linking together different classes that uses the same templated class. I found 2 workarounds, that will make it compile, but it's not really a solution. 1. don't do a staged compiling with linking object code 2. inlining the spezialized member functions. I'm looking for a solution that …

Member Avatar for StuXYZ
0
847
Member Avatar for monkey_king

Hey, does anyone know if it possible to have something like [CODE] #DEFINE NUM_DEC 4 printf("This is your value:%.NUM_DECf\n"); [/CODE] thanks in advance

Member Avatar for Prabakar
0
98
Member Avatar for monkey_king

Hi, I've written a program for statistic analysis that can be found here [url]http://staff.pubhealth.ku.dk/~ande/web/software/relate.html[/url] I want to make it portable and the program works on unix with the following compilers sun, intel and gcc It also compiles on windows with mingw and the intel compiler. I've installed ms studio, but …

Member Avatar for Nick Evan
0
104
Member Avatar for monkey_king

Hi, I was just wondering if adding debug symbols to my program, will slow down it's performance. I'm running linux. thanks in advance

Member Avatar for daviddoria
0
89
Member Avatar for monkey_king

Hi I'm trying to convert a linux/gcc program to windows/cl But I'm having some problems understanding the inner workings of the ide called microsoft visual studio c++ 2008 express. I've started a "new clr project", and then added the .hpp file, that contains the header. But the compiler/f7 says that …

Member Avatar for iDeveloper
0
230
Member Avatar for monkey_king

Hi, I was thinking about implementing piping and redirection in some of my programs. But I'm having difficilties getting started. Does anyone know were to read up on this area, or just what to google. Google only gives my tutorials on basic unix commandline usage. thanks in advance

Member Avatar for monkey_king
0
82
Member Avatar for monkey_king

I've made a program using gcc as a compiler. In my loops I've been using a uint type as the type of my loop variable. But now it seems that some systems doesn't support this type. Can I make a preprocessor conditional that does a #define uint to unsigned int …

Member Avatar for WaltP
0
158
Member Avatar for monkey_king

I wan't use the multimap on my own templated class. The following is a working example with a builtin type. [CODE=c++] int dat[5] = {0,6,3,7,3}; typedef std::multimap< int, int > asso; asso dict; for (int i=0;i<5;i++){ dict.insert(make_pair(dat[i],i)); } asso::iterator pos; for(pos=dict.begin(); pos!=dict.end() ;pos++) cout << pos->first <<" next "<< pos->second …

Member Avatar for monkey_king
0
188
Member Avatar for monkey_king

I've been overloading some methods for a template class. This means I can write my code in this way. [CODE=c++] myClass var3=var2+4; [/CODE] Is it possible to do it the otherway around like [CODE=c++] myClass var3=4+var2; [/CODE] I know that the end result will be the same, I was just …

Member Avatar for monkey_king
0
149
Member Avatar for monkey_king

Hi, I've been implementing my own array class, and I've finally started to use it. I do have one question, [CODE=c++] Array<int> ary1(3);ary1(0)=2;ary1(1)=4;ary1(2)=7; //just an array Array<int> ary2(3);ary2(0)=1;ary2(1)=2;ary2(2)=6; //just an array cout << ary1; cout << ary2; Array<int> ary3 = ary1+ary2; cout << ary3; //everything till this point works //is …

Member Avatar for dougy83
0
93
Member Avatar for monkey_king

Hi I'm doing a templated matrix class, and I'd like to be able to pass a function pointer to a function that uses the rows. [CODE=c++] template<typename T> T sum(Array<T> &a){ // a simple function that return the sum of an Array T res=0; for(int i=0;i<a.length();i++) res+=a(i); return res; } …

Member Avatar for monkey_king
0
8K
Member Avatar for monkey_king

I'm doing my own array template version of an array. I'm having some problems overloading a method. I'm doing a specifik version of a "print()" if the type of array is <char>,(i'm saving bools as char). this works without problems. I just needed to add a templete<> infront of my …

Member Avatar for monkey_king
0
112
Member Avatar for monkey_king

Hi, I'm doing a low-mem implementation of a matrix, than can contain values from 0-4, this is fine for my program. I input 4 values (each 2bit) into 1 char(8bit). I'm using bitpatterns and shifting to extract values. But this is of cause hidden from the user. I've done everything …

Member Avatar for ArkM
0
224
Member Avatar for monkey_king

Hi, I've been programming a lot of c code, and now I'm trying to set my mind into the c++ way of doing things. so I'm trying to avoid pointers, and use refs instead. As far as I understand pointers are to be avoided using stl's for instance. I have …

Member Avatar for ArkM
0
117
Member Avatar for monkey_king

Hi I have a some general questions, some are c others are c++ related. So I'll just post them here in the c++ forum. These question only relates to speed not so much design issues. So far most of my programming has just been about making it work. That is …

Member Avatar for Narue
0
151
Member Avatar for monkey_king

Hi, given a char(8bit's), I want to get the value of every 2bits, so that a char will contain 4 values. This is easily done with a shift left command (<<2). As far as I understand, char arrays are simply the different chars in consecutive order in the memory. so …

Member Avatar for monkey_king
0
2K
Member Avatar for monkey_king

Hi I'm doing a statistical mcmc model where I need some random numbers. I decided to use the ranrot-w generator. The random number only works when I call the randomnumber method directly, and not when i give the random number as an parameter to another function. that is rg.Random() !=random(rg) …

Member Avatar for monkey_king
0
156

The End.