2,384 Posted Topics

Member Avatar for gerard4143

[QUOTE=gerard4143;1040027]Is this the proper way to zero the first 12 bits of an address? [CODE]void *ans = (void*)((unsigned long)addr & [COLOR="Red"]((0UL - 1) ^ 0xfff)[/COLOR]);[/CODE] Where addr is any user process memory address.. Note this method works...I just want to know if there is a better way[/QUOTE] That kind of …

Member Avatar for Dave Sinkula
0
164
Member Avatar for Kombat

Used unsigned integral types when dealing with bits. [code]#include <stdio.h> #include <stdlib.h> int main() { unsigned short m1 = 0xf000, m2 = 0x0f00, m3 = 0x00f0, m4 = 0x000f; printf("%hu %hu %hu %hu\n", m1, m2, m3, m4); printf("%hx %hx %hx %hx\n", m1, m2, m3, m4); return 0; } /* my …

Member Avatar for Dave Sinkula
0
138
Member Avatar for Dewey1040
Member Avatar for sneekula

Q: Before signing the death certificate had you taken the man's pulse? A: No. Q: Did you listen for a heart beat? A: No. Q: Did you check for breathing? A: No. Q: So when you signed the death certificate you hadn't taken any steps to make sure the man …

Member Avatar for vegaseat
1
495
Member Avatar for Gem74

[QUOTE=Gem74;1037253]I saved "input_data.txt" in the header files, see below. [CODE]#include "input_data.txt.h"[/CODE][/QUOTE]Huh? If you're trying to open the file for input, you use this bit here: [CODE]ifstream inputFile;[/CODE] Open the file and read it?

Member Avatar for Fbody
0
245
Member Avatar for fatihpiristine

Use strcpy to copy a string. You've got more going wrong in that code, though. I think you're after something that might look a bit like this: [CODE]#include <string.h> typedef struct { int age; char name[50]; } Person; Person newperson(char *name, int age) { Person temp; strcpy(temp.name, name); temp.age = …

Member Avatar for fatihpiristine
0
99
Member Avatar for fraandres

How about a final else? And don't use the comma here: [CODE]else if (numtick >100,000)[/CODE]

Member Avatar for Dave Sinkula
0
411
Member Avatar for Ancient Dragon

One way it was done ages ago elseweb was [code], [quote], and [syntax]. The syntax tags were used for the "fancy" code tags. Quote in monospace to me would look stupid. [edit]Keeping the fonts, but limiting them, would also have handled the way [icode] is used. Some of the "common" …

Member Avatar for Dave Sinkula
0
490
Member Avatar for sgw

My usual advice is to always read all user input as a string. If you want a numeric value, attempt to perform a conversion. If the conversion fails, issue a message or something; otherwise you successfully obtained a numeric value, so continue.

Member Avatar for sgw
0
254
Member Avatar for A Tripolation
Member Avatar for mitsuevo

[URL="http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.5.6.4"]fmod[/URL]

Member Avatar for Dave Sinkula
0
78
Member Avatar for dinamit875

[CODE]team temp[1];[/CODE] This has only one element: [iCODE]temp[0][/iCODE]. [CODE][COLOR="Red"]temp[1][/COLOR] = teams1[(j-1)]; teams1[(j-1)] = teams1[j]; teams1[j] = [COLOR="Red"]temp[1][/COLOR];[/CODE]

Member Avatar for dinamit875
0
137
Member Avatar for zandiago

Two words ;) :[INDENT]Spare the rod, spoil the child.[/INDENT]IMO those who don't know what they are doing [I]REALLY[/I] screw it up. Whether that entails spankings or lack thereof, dunno.

Member Avatar for BestJewSinceJC
0
888
Member Avatar for yasaswyg

[CODE]while((c [COLOR="Red"]=[/COLOR] getchar())!= EOF)[/CODE] And what does your function return for non-alpha input?

Member Avatar for yasaswyg
0
139
Member Avatar for turbeauxpete
Member Avatar for Dave Sinkula
0
95
Member Avatar for Wtyy
Member Avatar for neithan

[QUOTE=neithan;1031915]Ok but, i'm sorry if this sound ignorant which probably will, isn't C89 too old? I look it up and this C99 thing works with those issues, right? Why still thinking of C89? (remember i'm a beginner)[/QUOTE]C89 is de facto standard for C, and it is also the base of …

Member Avatar for neithan
0
162
Member Avatar for neithan

I get an odd warning: [CODE]switch ( opcion ) [COLOR="Red"]// warning: unreachable code at beginning of switch statement[/COLOR] { case 1:[/CODE]I think this has something to do with using the language extension VLA: [CODE]float polinomio[n];[/CODE]I don't know exactly what the issue here is -- gcc is trying to clue me …

Member Avatar for Dave Sinkula
0
128
Member Avatar for lotrsimp12345

I had to patch some syntax errors to get to the link, so I'm not sure why you weren't seeing them. With regard to the linker errors: [url]http://parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] ?

Member Avatar for Dave Sinkula
0
144
Member Avatar for neithan

[QUOTE=neithan;1030800]What am i missing?[/QUOTE]Hmm. [QUOTE]Input: web char x -> w int x --> 119 char x -> e int x --> 101 char x -> b int x --> 98 Input: foo char x -> f int x --> 102 char x -> o int x --> 111 char x …

Member Avatar for neithan
0
137
Member Avatar for riahc3

[code]int main() { FILE *filetext; FILE *filecopied; char text[50]; filetext=fopen("filetext.txt","r"); filecopied=fopen("filecopied.txt","w"); if ( (filetext==NULL) || (filecopied==NULL) ) { printf ("A file cannot be opened"); return 1; } [COLOR="Red"]while ( fgets(text, sizeof text, filetext) ) { char first[10]; if ( sscanf(text, "%9s", first) == 1 ) { fprintf(filecopied, "%s\n", first); } …

Member Avatar for Tom Gunn
0
925
Member Avatar for cloisterham
Member Avatar for Tom Gunn
0
551
Member Avatar for itzaaron

You might find such a thing here, perhaps in the snippets, maybe a previous forum thread. So a search might be helpful to you.

Member Avatar for mrnutty
0
2K
Member Avatar for gebbit

For a value 0-9, you can just add [FONT=Courier New]'0'[/FONT] to get the corresponding digit character. [code]#include <stdio.h> int main(void) { char text[] = "StringX"; int digit; for (digit = 0; digit < 10; ++digit) { text[6] = [COLOR=Blue]digit + '0'[/COLOR]; puts(text); } return 0; } /* my output String0 …

Member Avatar for themoon49
0
2K
Member Avatar for kingcrim05

[CODE] fin.open("numlist.dat"); fout.open("numlist.dat");[/CODE] Perhaps first open for input. Then after you've extraced what you want and closed the file, then open the same file for output.

Member Avatar for Ancient Dragon
0
118
Member Avatar for raigs

This is array of pointers to string literals:[CODE]char *MONTH[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};[/CODE]String literals are not writable. Same here: [CODE]REPLACE("The month is: January."); // Should be: "The month is: Enero"[/CODE]

Member Avatar for Aia
0
98
Member Avatar for power_computer
Member Avatar for power_computer
0
263
Member Avatar for Odc

[QUOTE=Odc;1027764]Hi guys, I've got a simple bool 2D array that is set to false by default. I'm filling it with random 'true' values. I am then trying to make it symmetrical i.e. array[i][j] = array[j][i] However, this doesnt seem to be working and I was wondering why. I've been trying …

Member Avatar for twomers
0
95
Member Avatar for tomtetlaw

[url]http://c-faq.com/varargs/index.html[/url] [url]http://c-faq.com/varargs/varargs1.html[/url]

Member Avatar for Dave Sinkula
0
88
Member Avatar for Odc

I wrote some snippets on parsing some time ago. [url]http://www.daniweb.com/code/snippet216535.html[/url] [url]http://www.daniweb.com/code/snippet216569.html[/url] [url]http://www.daniweb.com/code/snippet216682.html[/url] [url]http://www.daniweb.com/code/snippet216681.html[/url] Perhaps something there will give you an idea for a starting point.

Member Avatar for Odc
0
118
Member Avatar for OSiRiSsk

[url]http://www.daniweb.com/tutorials/tutorial45806.html[/url] -- the "Read an Floating Point ..." links have additional possibilities better suited to your task.

Member Avatar for Aia
0
261
Member Avatar for itzaaron

[CODE]for ( int x=0; x<3; x++ )[COLOR="Red"];[/COLOR][/CODE] Do you know what the semicolon does to your intended loop?

Member Avatar for itzaaron
0
172
Member Avatar for tomtetlaw

Don't put data definitions in header files. Header guards will only ensure that only one copy exists in each source file in which it is included, but as you see you will get linker errors for multiple definitions. Put data and function definitions in source files. Move the data definition …

Member Avatar for Dave Sinkula
0
214
Member Avatar for luoyangke
Member Avatar for Dave Sinkula
0
113
Member Avatar for Ancient Dragon

[QUOTE=majestic0110;1001389]Maybe we could have an option to neg rep a member UPTO our maximum neg rep amount? I don't think I have ever neg repped anyone actually![/QUOTE]I had asked for this years ago, I believe: essentially the DevShed approach of choosing the amount of both positive and negative rep. I'd …

Member Avatar for VernonDozier
0
1K
Member Avatar for rmcummings

[QUOTE=rmcummings;1025357]I am new to C++ and am writing a program that will call other functions. I keep getting an error for a undeclared identifier for "vowel" in this section of code. Can anyone help?[/quote]I get different errors with the code you posted (which would have formatting preserved if you used …

Member Avatar for rmcummings
0
189
Member Avatar for James19142

[QUOTE=firstPerson;1023044][code]A = r+5(r-2) = 28 = r + 5r - 10 = [COLOR="Red"]28[/COLOR] //distributive rule = 6r - 10 = [COLOR="Red"]20[/COLOR] //add like trms[/code][/QUOTE]Where'd the 28 go and the 20 come from?

Member Avatar for mrnutty
-1
221
Member Avatar for hmortensen

You kinda need to know whether the binary contains LE or BE data. Some somewhat related FAQs: [url]http://c-faq.com/misc/endiantest.html[/url] [url]http://c-faq.com/cpp/ifendian.html[/url] [url]http://c-faq.com/misc/byteswap.html[/url] Or perhaps consider a text file.

Member Avatar for hmortensen
0
148
Member Avatar for riahc3

Change [CODE] [COLOR="Green"]do{ fgets(texto,50,archivopar);[/COLOR] if (i % 2 == 0) { fprintf(archivocopiado,"%s\n",texto); } if (archivopar!=EOF) { i=i+1; } [COLOR="Green"]}while(archivopar!=EOF);[/COLOR][/CODE]to[CODE] [COLOR="Red"]while(fgets(texto,sizeof texto,archivopar)) {[/COLOR] if (i % 2 == 0) { fprintf(archivocopiado,"%s\n",texto); } if (archivopar!=EOF) { i=i+1; } [COLOR="Red"]}[/COLOR][/CODE]...more or less.

Member Avatar for Gaiety
0
202
Member Avatar for Free1ancer

[QUOTE][CODE]template <typename Comparable> LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2) //<----------------------problem code[/CODE][/QUOTE] [CODE]template <typename Comparable> [COLOR="Red"]typename LeftistHeap<Comparable>::[/COLOR]LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)[/CODE]? [url]http://groups.google.com/group/comp.lang.c++/browse_thread/thread/830178e40acca27a/2825ed52b5ae3fac?ie=UTF-8&q=group%3Acomp.lang.c%2B%2B+expected+constructor+destructor+or+type+conversion&pli=1[/url]

Member Avatar for Free1ancer
0
124
Member Avatar for ankur_

[url]http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_skip.aspx[/url] ?

Member Avatar for ankur_
0
89
Member Avatar for orium

[code]//Here is when you help me drawing the rectangle :)[/code]Funny. :) Assuming a solid rectangle, you have nested loops: outer loop counts rows, inner loop counts columns; inner loop contains output of char1, at the end of the inner loop you output a newline. A typical loop would be such …

Member Avatar for maverick420
0
1K
Member Avatar for needhelpe
Member Avatar for eranga262154

Why not just add two int's and let the compiler perform the crap you don't have to?

Member Avatar for kia_barghi60
0
282
Member Avatar for five01

Would you like us to write the whole thing for you and pretty it up nice? [URL="http://www.daniweb.com/forums/announcement8-2.html"]Or can you show us where it is that you need assistance[/URL]?

Member Avatar for Dave Sinkula
0
36
Member Avatar for infern0

Some starters: Sort out your confusion about strings and numbers. Assignment is [ICODE]=[/ICODE], comparison is [ICODE]==[/ICODE]. Multiline blocks are not determined by indentation in this curly-brace language.

Member Avatar for Phil++
0
89
Member Avatar for WethiL

You might want to add the compiler switch -Wall to turn up more errors and warnings. I can't build what you posted. [edit]With some rearranging and reasonable guesses for changes to your code, I was able to build it and it segfaults here in [ICODE]correctNumber[/ICODE]: [CODE] else if ( ptr->next!=NULL …

Member Avatar for Dave Sinkula
0
113
Member Avatar for Hoey33

[URL="http://www.daniweb.com/forums/announcement118-2.html"]Post the code of your attempt[/URL].

Member Avatar for MrNoob
0
126
Member Avatar for Web_Sailor

[QUOTE=amrith92;1019673]You could try this: [CODE] fgets(line, 1000, in); while ([COLOR="Red"]! feof(in)[/COLOR]) { // ... }[/CODE][/QUOTE][URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351"]Why it's bad to use feof() to control a loop[/URL] [edit]I think the [ICODE]"rt+"[/ICODE] mode is a nonstandard extension meaning [ICODE]"r+"[/ICODE]. [edit]And it might be preferable to do [CODE]fgets(line, [COLOR="Green"]sizeof line[/COLOR], in);[/CODE] instead of [code]fgets(line, [COLOR="Red"]1000[/COLOR], …

Member Avatar for Web_Sailor
0
8K
Member Avatar for Dazaa

[QUOTE=Gaiety;1018153]instead of [CODE]p = malloc(length+1); [/CODE] use [CODE]p = (char *) malloc(length+1); [/CODE] [/QUOTE]In C++ the cast is necessary, [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351"]in C prefer not to cast[/URL].

Member Avatar for Dave Sinkula
0
147

The End.